Hello i’ve created an automation using VisionUI , now i did take the code whos in ‘json’ and translate it to Python, but on python selenium the ‘clicks’ dont work.
i can run the script on VisionUI and it works but when i translate it to python it cant click the proper buttons.
i was writing my code in python at first but had a simillar problem had stuck on a button whos on double iframe and hidden and couldnt catch the link.
however on vision ui and in json it works , but i wanna make it work in python
here is my json ‘code’
{
"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": "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=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": "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-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": ""
}
]
}
and here is the python code
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()
Greg Fotopoulos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.