Здравствуйте, я создал автоматизацию с помощью VisionUI, теперь я взял код в формате «json» и перевел его на Python, но на Python Selenium «клики» не работают.
Я могу запустить скрипт на VisionUI, и он работает, но когда я перевожу его на Python, он не может нажимать нужные кнопки.
Сначала я писал свой код на Python, но у меня возникла аналогичная проблема: застряла кнопка, которая в двойном iframe, скрытом и не смог поймать ссылку.
однако в Vision UI и в json это работает, но я хочу, чтобы это работало в Python
вот мой json-код
{
"Name": "downloadzoom",
"CreationDate": "2024-8-3",
"Commands": [
{
"Command": "open",
"Target": "https://zoom.us/signin#/login",
"Value": "",
"Description": ""
},
{
"Command": "type",
"Target": "id=email",
"Value": "[email protected]",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "type",
"Target": "id=password",
"Value": "1234",
"Targets": [
"id=password",
"name=password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=email",
"Value": "",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=email",
"Value": "",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=email",
"Value": "",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "type",
"Target": "id=email",
"Value": "[email protected]",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=password",
"Value": "",
"Targets": [
"id=password",
"name=new-password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=password",
"Value": "",
"Targets": [
"id=password",
"name=new-password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=password",
"Value": "",
"Targets": [
"id=password",
"name=new-password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "type",
"Target": "id=password",
"Value": "1234",
"Targets": [
"id=password",
"name=password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=//*[@id=\"js_btn_login\"]/span",
"Value": "",
"Targets": [
"xpath=//*[@id=\"js_btn_login\"]/span",
"xpath=//div[4]/button/span",
"css=#js_btn_login > span"
],
"Description": ""
},
{
"Command": "clickAndWait",
"Target": "linkText=Recordings",
"Value": "",
"Targets": [
"linkText=Recordings",
"xpath=//*[@id=\"personal-nav-list\"]/li[9]/a",
"xpath=//li[9]/a",
"css=#personal-nav-list > li:nth-child(9) > a"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i",
"Value": "",
"Targets": [
"xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i",
"xpath=//td[6]/div/div/div/div/button/i",
"css=#recordingTable > div.zm-table__body-wrapper.is-scrolling-none > div > div.zm-scrollbar__wrap > div > table > tbody > tr > td.zm-table_2_column_12.is-right.cell-wrapper > div > div > div > div > button > i"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=//*[@id=\"dropdown_item_dropdown-menu-9406-0\"]/span/div",
"Value": "",
"Targets": [
"xpath=//*[@id=\"dropdown_item_dropdown-menu-9406-0\"]/span/div",
"xpath=//span/div",
"css=#dropdown_item_dropdown-menu-9406-0 > span > div"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=/html/body/div[4]/div/div[3]/span/button/span",
"Value": "",
"Targets": [
"xpath=/html/body/div[4]/div/div[3]/span/button/span",
"xpath=//div[3]/span/button/span",
"css=body > div.zm-dialog__wrapper > div > div.zm-dialog__footer > span > button.mr-8.zm-button--primary.zm-button--small.zm-button > span"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=headerPic",
"Value": "",
"Targets": [
"id=headerPic",
"xpath=//*[@id=\"headerPic\"]",
"xpath=//img[@id='headerPic']",
"xpath=//ul[4]/li[6]/a/img",
"css=#headerPic"
],
"Description": ""
},
{
"Command": "clickAndWait",
"Target": "xpath=//*[@id=\"btnLogout\"]/span",
"Value": "",
"Targets": [
"xpath=//*[@id=\"btnLogout\"]/span",
"xpath=//a[3]/span",
"css=#btnLogout > span"
],
"Description": ""
}
]
}
а вот код Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def execute_commands(driver, commands):
for command in commands:
logging.info(f"Executing command: {command['Command']} with target: {command['Target']}")
try:
if command["Command"] == "open":
driver.get(command["Target"])
elif command["Command"] == "click":
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, command["Target"].split('=')[1]))
)
element.click()
elif command["Command"] == "type":
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, command["Target"].split('=')[1]))
)
element.clear()
element.send_keys(command["Value"])
elif command["Command"] == "clickAndWait":
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.LINK_TEXT, command["Target"].split('=')[1]))
)
element.click()
else:
logging.error(f"Command {command['Command']} not recognized")
except Exception as e:
logging.error(f"Exception occurred while executing command: {command['Command']} with target: {command['Target']}")
logging.error(str(e))
driver.save_screenshot(f"screenshot_{command['Command']}_{command['Target'].replace('=', '_').replace('/', '_')}.png")
raise
if __name__ == "__main__":
commands = [
{"Command": "open", "Target": "https://zoom.us/signin#/login", "Value": "", "Description": ""},
{"Command": "type", "Target": "id=email", "Value": "[email protected]", "Targets": ["id=email", "name=new-email", "xpath=//*[@id=\"email\"]", "xpath=//input[@id='email']", "xpath=//input", "css=#email"], "Description": ""},
{"Command": "type", "Target": "id=password", "Value": "Gp0Gg390z@*0", "Targets": ["id=password", "name=password", "xpath=//*[@id=\"password\"]", "xpath=//input[@id='password']", "xpath=//div[2]/div/div/input", "css=#password"], "Description": ""},
{"Command": "click", "Target": "id=onetrust-accept-btn-handler", "Value": "", "Targets": ["id=onetrust-accept-btn-handler", "xpath=//*[@id=\"onetrust-accept-btn-handler\"]", "xpath=//button[@id='onetrust-accept-btn-handler']", "xpath=//div[2]/div/div/button[2]", "css=#onetrust-accept-btn-handler"], "Description": ""},
{"Command": "open", "Target": "https://zoom.us/signin#/login", "Value": "", "Description": ""},
{"Command": "click", "Target": "id=email", "Value": "", "Targets": ["id=email", "name=new-email", "xpath=//*[@id=\"email\"]", "xpath=//input[@id='email']", "xpath=//input", "css=#email"], "Description": ""},
{"Command": "type", "Target": "id=email", "Value": "[email protected]", "Targets": ["id=email", "name=new-email", "xpath=//*[@id=\"email\"]", "xpath=//input[@id='email']", "xpath=//input", "css=#email"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"app\"]/div/div[2]/div/div/form/div[2]/div/div/label", "Value": "", "Targets": ["xpath=//*[@id=\"app\"]/div/div[2]/div/div/form/div[2]/div/div/label", "xpath=//div[2]/div/div/label", "css=#app > div > div.layout-main > div > div:nth-child(2) > form > div.zm-form-item.zm-form-password.is-no-asterisk > div > div > label"], "Description": ""},
{"Command": "click", "Target": "id=password", "Value": "", "Targets": ["id=password", "name=new-password", "xpath=//*[@id=\"password\"]", "xpath=//input[@id='password']", "xpath=//div[2]/div/div/input", "css=#password"], "Description": ""},
{"Command": "type", "Target": "id=password", "Value": "Qb9V[4:K6", "Targets": ["id=password", "name=password", "xpath=//*[@id=\"password\"]", "xpath=//input[@id='password']", "xpath=//div[2]/div/div/input", "css=#password"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"js_btn_login\"]/span", "Value": "", "Targets": ["xpath=//*[@id=\"js_btn_login\"]/span", "xpath=//div[4]/button/span", "css=#js_btn_login > span"], "Description": ""},
{"Command": "clickAndWait", "Target": "linkText=Recordings", "Value": "", "Targets": ["linkText=Recordings", "xpath=//*[@id=\"personal-nav-list\"]/li[9]/a", "xpath=//li[9]/a", "css=#personal-nav-list > li:nth-child(9) > a"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i", "Value": "", "Targets": ["xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i", "xpath=//td[6]/div/div/div/div/button/i", "css=#recordingTable > div.zm-table__body-wrapper.is-scrolling-none > div > div.zm-scrollbar__wrap > div > table > tbody > tr > td.zm-table_2_column_12.is-right.cell-wrapper > div > div > div > div > button > i"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"dropdown_item_dropdown-menu-8685-0\"]/span/div", "Value": "", "Targets": ["xpath=//*[@id=\"dropdown_item_dropdown-menu-8685-0\"]/span/div", "xpath=//span/div", "css=#dropdown_item_dropdown-menu-8685-0 > span > div"], "Description": ""},
{"Command": "click", "Target": "xpath=/html/body/div[4]/div/div[3]/span/button/span", "Value": "", "Targets": ["xpath=/html/body/div[4]/div/div[3]/span/button/span", "xpath=//div[3]/span/button/span", "css=body > div.zm-dialog__wrapper > div > div.zm-dialog__footer > span > button.mr-8.zm-button--primary.zm-button--small.zm-button > span"], "Description": ""},
{"Command": "click", "Target": "id=headerPic", "Value": "", "Targets": ["id=headerPic", "xpath=//*[@id=\"headerPic\"]", "xpath=//img[@id='headerPic']", "xpath=//ul[4]/li[6]/a/img", "css=#headerPic"], "Description": ""},
{"Command": "clickAndWait", "Target": "xpath=//*[@id=\"btnLogout\"]/span", "Value": "", "Targets": ["xpath=//*[@id=\"btnLogout\"]/span", "xpath=//a[3]/span", "css=#btnLogout > span"], "Description": ""}
]
# Set Chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-search-engine-choice-screen")
# Create WebDriver instance with options
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
driver.implicitly_wait(10)
try:
# Execute commands
execute_commands(driver, commands)
finally:
driver.quit()
исходный код Python
import time
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
import pyautogui
# Add your login credentials here
username_str = '[email protected]'
password_str = '1234'
def download_file_via_js(driver, file_url, download_path):
js_code = f'''
var a = document.createElement('a');
a.href = "{file_url}";
a.download = "{os.path.basename(download_path)}";
var ev = document.createEvent("MouseEvents");
ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0,
false, false, false, false, 0, null);
a.dispatchEvent(ev);
'''
driver.execute_script(js_code)
def hover_and_click_more_icon(driver):
try:
more_icon_xpath = '//*[@id="recordingTable"]/div[2]/div/div[1]/div/table/tbody/tr/td[6]/div/div/div/div/button'
more_icon = WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.XPATH, more_icon_xpath))
)
# Click the element directly by its XPath
driver.find_element(By.XPATH, more_icon_xpath).click()
print("More icon clicked successfully.")
except Exception as e:
print("Failed to find or click the More icon.")
driver.save_screenshot("more_icon_error.png")
print(e)
def login_and_download(driver, username, password):
driver.get('https://zoom.us/signin')
# Accept cookies if prompted
try:
cookie_accept_button = WebDriverWait(driver, 60).until(
EC.element_to_be_clickable((By.ID, "onetrust-accept-btn-handler"))
)
cookie_accept_button.click()
except Exception as e:
print("No cookie consent popup found or failed to click accept button.")
print(e)
# Login
username_box = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.ID, 'email')))
username_box.send_keys(username)
password_box = driver.find_element(By.ID, 'password')
password_box.send_keys(password)
password_box.send_keys(Keys.RETURN)
time.sleep(5) # Wait for login to complete
# Wait for the login process to complete and navigate to the profile page
try:
WebDriverWait(driver, 60).until(EC.url_contains("zoom.us/profile"))
print("Login successful and navigated to profile page.")
except Exception as e:
print("Login failed or did not navigate to profile page.")
driver.save_screenshot("login_failed.png")
raise e
# Navigate to recordings
driver.get('https://zoom.us/recording')
time.sleep(5) # Wait for recordings page to load
# Select an option from the dropdown
try:
select = Select(WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "#recordingTable > div.zm-table__body-wrapper.is-scrolling-left > div > div.zm-scrollbar__wrap > div > table > tbody > tr > td.zm-table_2_column_12.is-right.is-flip.cell-wrapper > div > div > div > div > button > i"))
))
select.select_by_index(2)
print("Selected the third option in the dropdown.")
except Exception as e:
print("Failed to select an option from the dropdown.")
driver.save_screenshot("dropdown_selection_error.png")
print(e)
# Find and click the "More" icon
hover_and_click_more_icon(driver)
time.sleep(2) # Wait for dropdown to appear
# Attempt to locate and click the download button
try:
download_link = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, '//div[contains(text(), "Download (1 files)")]'))
)
download_link.click()
print("Download link clicked successfully.")
# Wait for iframe to appear and switch to it
iframe = WebDriverWait(driver, 30).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[contains(@src, "download")]'))
)
# Now you can locate and interact with the download link within the iframe
download_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, '//a[contains(@class, "download-btn")]'))
)
# Get the href of the download button
download_url = download_button.get_attribute('href')
# Define the download path
download_path = os.path.join(os.getcwd(), 'downloaded_recording.mp4')
# Download the file using JavaScript
download_file_via_js(driver, download_url, download_path)
print("File downloaded successfully.")
# Switch back to the default content
driver.switch_to.default_content()
except Exception as e:
print("Download link not found or not clickable. Trying PyAutoGUI method.")
driver.save_screenshot("download_link_error.png")
# Attempt to locate the download button using PyAutoGUI
attempts = 3
while attempts > 0:
try:
download_button_location = pyautogui.locateCenterOnScreen('C:\\Users\\g.fotopoulos\\.vscode\\images\\download_button.png', confidence=0.8)
if download_button_location is not None:
pyautogui.click(download_button_location)
print("Download button clicked successfully using PyAutoGUI.")
break
except pyautogui.ImageNotFoundException:
print("Download button not found. Retrying...")
attempts -= 1
time.sleep(2) # Wait before retrying
else:
print("Failed to locate the download button after multiple attempts.")
if __name__ == "__main__":
driver = webdriver.Chrome()
try:
login_and_download(driver, username_str, password_str)
finally:
driver.quit()
Подробнее здесь: https://stackoverflow.com/questions/788 ... n-visio-ui
Перевод JSON в Python Пользовательский интерфейс Visio ⇐ Python
Программы на Python
1722720999
Anonymous
Здравствуйте, я создал автоматизацию с помощью VisionUI, теперь я взял код в формате «json» и перевел его на Python, но на Python Selenium «клики» не работают.
Я могу запустить скрипт на VisionUI, и он работает, но когда я перевожу его на Python, он не может нажимать нужные кнопки.
Сначала я писал свой код на Python, но у меня возникла аналогичная проблема: застряла кнопка, которая в двойном iframe, скрытом и не смог поймать ссылку.
однако в Vision UI и в json это работает, но я хочу, чтобы это работало в Python
вот мой json-код
{
"Name": "downloadzoom",
"CreationDate": "2024-8-3",
"Commands": [
{
"Command": "open",
"Target": "https://zoom.us/signin#/login",
"Value": "",
"Description": ""
},
{
"Command": "type",
"Target": "id=email",
"Value": "[email protected]",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "type",
"Target": "id=password",
"Value": "1234",
"Targets": [
"id=password",
"name=password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=email",
"Value": "",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=email",
"Value": "",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=email",
"Value": "",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "type",
"Target": "id=email",
"Value": "[email protected]",
"Targets": [
"id=email",
"name=new-email",
"xpath=//*[@id=\"email\"]",
"xpath=//input[@id='email']",
"xpath=//input",
"css=#email"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=password",
"Value": "",
"Targets": [
"id=password",
"name=new-password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=password",
"Value": "",
"Targets": [
"id=password",
"name=new-password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=password",
"Value": "",
"Targets": [
"id=password",
"name=new-password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "type",
"Target": "id=password",
"Value": "1234",
"Targets": [
"id=password",
"name=password",
"xpath=//*[@id=\"password\"]",
"xpath=//input[@id='password']",
"xpath=//div[2]/div/div/input",
"css=#password"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=//*[@id=\"js_btn_login\"]/span",
"Value": "",
"Targets": [
"xpath=//*[@id=\"js_btn_login\"]/span",
"xpath=//div[4]/button/span",
"css=#js_btn_login > span"
],
"Description": ""
},
{
"Command": "clickAndWait",
"Target": "linkText=Recordings",
"Value": "",
"Targets": [
"linkText=Recordings",
"xpath=//*[@id=\"personal-nav-list\"]/li[9]/a",
"xpath=//li[9]/a",
"css=#personal-nav-list > li:nth-child(9) > a"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i",
"Value": "",
"Targets": [
"xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i",
"xpath=//td[6]/div/div/div/div/button/i",
"css=#recordingTable > div.zm-table__body-wrapper.is-scrolling-none > div > div.zm-scrollbar__wrap > div > table > tbody > tr > td.zm-table_2_column_12.is-right.cell-wrapper > div > div > div > div > button > i"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=//*[@id=\"dropdown_item_dropdown-menu-9406-0\"]/span/div",
"Value": "",
"Targets": [
"xpath=//*[@id=\"dropdown_item_dropdown-menu-9406-0\"]/span/div",
"xpath=//span/div",
"css=#dropdown_item_dropdown-menu-9406-0 > span > div"
],
"Description": ""
},
{
"Command": "click",
"Target": "xpath=/html/body/div[4]/div/div[3]/span/button/span",
"Value": "",
"Targets": [
"xpath=/html/body/div[4]/div/div[3]/span/button/span",
"xpath=//div[3]/span/button/span",
"css=body > div.zm-dialog__wrapper > div > div.zm-dialog__footer > span > button.mr-8.zm-button--primary.zm-button--small.zm-button > span"
],
"Description": ""
},
{
"Command": "click",
"Target": "id=headerPic",
"Value": "",
"Targets": [
"id=headerPic",
"xpath=//*[@id=\"headerPic\"]",
"xpath=//img[@id='headerPic']",
"xpath=//ul[4]/li[6]/a/img",
"css=#headerPic"
],
"Description": ""
},
{
"Command": "clickAndWait",
"Target": "xpath=//*[@id=\"btnLogout\"]/span",
"Value": "",
"Targets": [
"xpath=//*[@id=\"btnLogout\"]/span",
"xpath=//a[3]/span",
"css=#btnLogout > span"
],
"Description": ""
}
]
}
а вот код Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def execute_commands(driver, commands):
for command in commands:
logging.info(f"Executing command: {command['Command']} with target: {command['Target']}")
try:
if command["Command"] == "open":
driver.get(command["Target"])
elif command["Command"] == "click":
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, command["Target"].split('=')[1]))
)
element.click()
elif command["Command"] == "type":
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, command["Target"].split('=')[1]))
)
element.clear()
element.send_keys(command["Value"])
elif command["Command"] == "clickAndWait":
element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.LINK_TEXT, command["Target"].split('=')[1]))
)
element.click()
else:
logging.error(f"Command {command['Command']} not recognized")
except Exception as e:
logging.error(f"Exception occurred while executing command: {command['Command']} with target: {command['Target']}")
logging.error(str(e))
driver.save_screenshot(f"screenshot_{command['Command']}_{command['Target'].replace('=', '_').replace('/', '_')}.png")
raise
if __name__ == "__main__":
commands = [
{"Command": "open", "Target": "https://zoom.us/signin#/login", "Value": "", "Description": ""},
{"Command": "type", "Target": "id=email", "Value": "[email protected]", "Targets": ["id=email", "name=new-email", "xpath=//*[@id=\"email\"]", "xpath=//input[@id='email']", "xpath=//input", "css=#email"], "Description": ""},
{"Command": "type", "Target": "id=password", "Value": "Gp0Gg390z@*0", "Targets": ["id=password", "name=password", "xpath=//*[@id=\"password\"]", "xpath=//input[@id='password']", "xpath=//div[2]/div/div/input", "css=#password"], "Description": ""},
{"Command": "click", "Target": "id=onetrust-accept-btn-handler", "Value": "", "Targets": ["id=onetrust-accept-btn-handler", "xpath=//*[@id=\"onetrust-accept-btn-handler\"]", "xpath=//button[@id='onetrust-accept-btn-handler']", "xpath=//div[2]/div/div/button[2]", "css=#onetrust-accept-btn-handler"], "Description": ""},
{"Command": "open", "Target": "https://zoom.us/signin#/login", "Value": "", "Description": ""},
{"Command": "click", "Target": "id=email", "Value": "", "Targets": ["id=email", "name=new-email", "xpath=//*[@id=\"email\"]", "xpath=//input[@id='email']", "xpath=//input", "css=#email"], "Description": ""},
{"Command": "type", "Target": "id=email", "Value": "[email protected]", "Targets": ["id=email", "name=new-email", "xpath=//*[@id=\"email\"]", "xpath=//input[@id='email']", "xpath=//input", "css=#email"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"app\"]/div/div[2]/div/div/form/div[2]/div/div/label", "Value": "", "Targets": ["xpath=//*[@id=\"app\"]/div/div[2]/div/div/form/div[2]/div/div/label", "xpath=//div[2]/div/div/label", "css=#app > div > div.layout-main > div > div:nth-child(2) > form > div.zm-form-item.zm-form-password.is-no-asterisk > div > div > label"], "Description": ""},
{"Command": "click", "Target": "id=password", "Value": "", "Targets": ["id=password", "name=new-password", "xpath=//*[@id=\"password\"]", "xpath=//input[@id='password']", "xpath=//div[2]/div/div/input", "css=#password"], "Description": ""},
{"Command": "type", "Target": "id=password", "Value": "Qb9V[4:K6", "Targets": ["id=password", "name=password", "xpath=//*[@id=\"password\"]", "xpath=//input[@id='password']", "xpath=//div[2]/div/div/input", "css=#password"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"js_btn_login\"]/span", "Value": "", "Targets": ["xpath=//*[@id=\"js_btn_login\"]/span", "xpath=//div[4]/button/span", "css=#js_btn_login > span"], "Description": ""},
{"Command": "clickAndWait", "Target": "linkText=Recordings", "Value": "", "Targets": ["linkText=Recordings", "xpath=//*[@id=\"personal-nav-list\"]/li[9]/a", "xpath=//li[9]/a", "css=#personal-nav-list > li:nth-child(9) > a"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i", "Value": "", "Targets": ["xpath=//*[@id=\"recordingTable\"]/div[3]/div/div/div/table/tbody/tr/td[6]/div/div/div/div/button/i", "xpath=//td[6]/div/div/div/div/button/i", "css=#recordingTable > div.zm-table__body-wrapper.is-scrolling-none > div > div.zm-scrollbar__wrap > div > table > tbody > tr > td.zm-table_2_column_12.is-right.cell-wrapper > div > div > div > div > button > i"], "Description": ""},
{"Command": "click", "Target": "xpath=//*[@id=\"dropdown_item_dropdown-menu-8685-0\"]/span/div", "Value": "", "Targets": ["xpath=//*[@id=\"dropdown_item_dropdown-menu-8685-0\"]/span/div", "xpath=//span/div", "css=#dropdown_item_dropdown-menu-8685-0 > span > div"], "Description": ""},
{"Command": "click", "Target": "xpath=/html/body/div[4]/div/div[3]/span/button/span", "Value": "", "Targets": ["xpath=/html/body/div[4]/div/div[3]/span/button/span", "xpath=//div[3]/span/button/span", "css=body > div.zm-dialog__wrapper > div > div.zm-dialog__footer > span > button.mr-8.zm-button--primary.zm-button--small.zm-button > span"], "Description": ""},
{"Command": "click", "Target": "id=headerPic", "Value": "", "Targets": ["id=headerPic", "xpath=//*[@id=\"headerPic\"]", "xpath=//img[@id='headerPic']", "xpath=//ul[4]/li[6]/a/img", "css=#headerPic"], "Description": ""},
{"Command": "clickAndWait", "Target": "xpath=//*[@id=\"btnLogout\"]/span", "Value": "", "Targets": ["xpath=//*[@id=\"btnLogout\"]/span", "xpath=//a[3]/span", "css=#btnLogout > span"], "Description": ""}
]
# Set Chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-search-engine-choice-screen")
# Create WebDriver instance with options
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
driver.implicitly_wait(10)
try:
# Execute commands
execute_commands(driver, commands)
finally:
driver.quit()
исходный код Python
import time
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
import pyautogui
# Add your login credentials here
username_str = '[email protected]'
password_str = '1234'
def download_file_via_js(driver, file_url, download_path):
js_code = f'''
var a = document.createElement('a');
a.href = "{file_url}";
a.download = "{os.path.basename(download_path)}";
var ev = document.createEvent("MouseEvents");
ev.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0,
false, false, false, false, 0, null);
a.dispatchEvent(ev);
'''
driver.execute_script(js_code)
def hover_and_click_more_icon(driver):
try:
more_icon_xpath = '//*[@id="recordingTable"]/div[2]/div/div[1]/div/table/tbody/tr/td[6]/div/div/div/div/button'
more_icon = WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.XPATH, more_icon_xpath))
)
# Click the element directly by its XPath
driver.find_element(By.XPATH, more_icon_xpath).click()
print("More icon clicked successfully.")
except Exception as e:
print("Failed to find or click the More icon.")
driver.save_screenshot("more_icon_error.png")
print(e)
def login_and_download(driver, username, password):
driver.get('https://zoom.us/signin')
# Accept cookies if prompted
try:
cookie_accept_button = WebDriverWait(driver, 60).until(
EC.element_to_be_clickable((By.ID, "onetrust-accept-btn-handler"))
)
cookie_accept_button.click()
except Exception as e:
print("No cookie consent popup found or failed to click accept button.")
print(e)
# Login
username_box = WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.ID, 'email')))
username_box.send_keys(username)
password_box = driver.find_element(By.ID, 'password')
password_box.send_keys(password)
password_box.send_keys(Keys.RETURN)
time.sleep(5) # Wait for login to complete
# Wait for the login process to complete and navigate to the profile page
try:
WebDriverWait(driver, 60).until(EC.url_contains("zoom.us/profile"))
print("Login successful and navigated to profile page.")
except Exception as e:
print("Login failed or did not navigate to profile page.")
driver.save_screenshot("login_failed.png")
raise e
# Navigate to recordings
driver.get('https://zoom.us/recording')
time.sleep(5) # Wait for recordings page to load
# Select an option from the dropdown
try:
select = Select(WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "#recordingTable > div.zm-table__body-wrapper.is-scrolling-left > div > div.zm-scrollbar__wrap > div > table > tbody > tr > td.zm-table_2_column_12.is-right.is-flip.cell-wrapper > div > div > div > div > button > i"))
))
select.select_by_index(2)
print("Selected the third option in the dropdown.")
except Exception as e:
print("Failed to select an option from the dropdown.")
driver.save_screenshot("dropdown_selection_error.png")
print(e)
# Find and click the "More" icon
hover_and_click_more_icon(driver)
time.sleep(2) # Wait for dropdown to appear
# Attempt to locate and click the download button
try:
download_link = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, '//div[contains(text(), "Download (1 files)")]'))
)
download_link.click()
print("Download link clicked successfully.")
# Wait for iframe to appear and switch to it
iframe = WebDriverWait(driver, 30).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[contains(@src, "download")]'))
)
# Now you can locate and interact with the download link within the iframe
download_button = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.XPATH, '//a[contains(@class, "download-btn")]'))
)
# Get the href of the download button
download_url = download_button.get_attribute('href')
# Define the download path
download_path = os.path.join(os.getcwd(), 'downloaded_recording.mp4')
# Download the file using JavaScript
download_file_via_js(driver, download_url, download_path)
print("File downloaded successfully.")
# Switch back to the default content
driver.switch_to.default_content()
except Exception as e:
print("Download link not found or not clickable. Trying PyAutoGUI method.")
driver.save_screenshot("download_link_error.png")
# Attempt to locate the download button using PyAutoGUI
attempts = 3
while attempts > 0:
try:
download_button_location = pyautogui.locateCenterOnScreen('C:\\Users\\g.fotopoulos\\.vscode\\images\\download_button.png', confidence=0.8)
if download_button_location is not None:
pyautogui.click(download_button_location)
print("Download button clicked successfully using PyAutoGUI.")
break
except pyautogui.ImageNotFoundException:
print("Download button not found. Retrying...")
attempts -= 1
time.sleep(2) # Wait before retrying
else:
print("Failed to locate the download button after multiple attempts.")
if __name__ == "__main__":
driver = webdriver.Chrome()
try:
login_and_download(driver, username_str, password_str)
finally:
driver.quit()
Подробнее здесь: [url]https://stackoverflow.com/questions/78829204/json-to-python-translation-visio-ui[/url]
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Перевод поведения и связанный с ним перевод модели
Anonymous » » в форуме PhpЯ искал в Интернете 1000000000000000 раз и не могу найти четкого решения для этой проблемы.
это моя часть перевода модели CertificateType:
public $actsAs = array('Translate'=>array('title','description')) ;
и модель сертификата:
public... - 0 Ответы
- 63 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Перевод строки C++ преобразован в возврат каретки и перевод строки
Anonymous » » в форуме C++Я пишу файл, который должен сохранять числовые данные в виде символов, чтобы их можно было прочитать другой, уже разработанной программой. До сих пор это было достаточно просто в исполнении, но у меня возникли проблемы с сохранением цифры 10,... - 0 Ответы
- 74 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Невозможно запустить макрос Visio с помощью Python
Anonymous » » в форуме PythonЯ пытаюсь запустить макрос Visio с помощью Python. Я получил это до сих пор, но это не работает. Я получаю ошибку: AttributeError: .Run при вызове doc.Application.Run
if os.path.exists( Drawing1.vsdm ):
visio = win32com.client.Dispatch(... - 0 Ответы
- 22 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Передайте строку в таблицу данных Visio Shape, используя Python
Anonymous » » в форуме PythonЯ пытаюсь передать значение строкового значения в таблицу данных Visio, но я могу передать значение номера в таблицу формы Visio и когда проход строковой значения Python бросает ошибку.
Пожалуйста, пожалуйста Помогите мне, что не хватало, я сделал.... - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Передайте строку в таблицу данных Visio Shape, используя Python
Anonymous » » в форуме PythonЯ пытаюсь передать значение строкового значения в таблицу данных Visio, но я могу передать значение номера в таблицу формы Visio и когда проход строковой значения Python бросает ошибку.
Пожалуйста, пожалуйста Помогите мне, что не хватало, я сделал.... - 0 Ответы
- 9 Просмотры
-
Последнее сообщение Anonymous
-
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...