from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import random
import select
driver = webdriver.Chrome('ChromeDriver')
driver.get("https://devbusiness.tunai.io/login")
time.sleep(2)
driver.maximize_window()
#log in credentials
username = driver.find_element(By.NAME, "loginUsername");
username.send_keys("dayon@tunai");
password = driver.find_element(By.NAME, "loginPassword");
password.send_keys("12341234");
login = driver.find_element(By.XPATH,"//*[@id='app']/div/div/div/div/div/div[2]/form/div[4]/button");
login.submit();
time.sleep(3)
driver.get("https://devbusiness.tunai.io/dashboard/my_salon_user")
time.sleep(3)
randomUsername = random.choice(["dayon.salon3@tunai","dayonmanager@tunai","Dayon.der@tunai"])
driver.find_element(By.XPATH, "//tbody[@role='rowgroup']/tr[@role='row']/td/a[text()='"+ randomUsername +"']").click()
print("Username selected: ", randomUsername)
time.sleep(5)
driver.find_element(By.XPATH,"//*[@id='page-content']/div/div[3]/div/div[2]/div/div/div[2]/div/div[1]/header/a").click()
time.sleep(5)
# Get the list of elements
elements = driver.find_elements(By.CLASS_NAME,'custom-control-input')
# Select a random element from the list
random_element = random.choice(elements)
driver.execute_script("arguments[0].click();", random_element)
# Click on the selected element
random_element.click()
print("Element selected: ", random_element)
time.sleep(5)
driver.find_element(By.XPATH,"//*[@id='accKey']").click()
time.sleep(5)
我已经添加了“argument.click[]"、“webdriver等待EC可单击”,但仍然显示“元素不可交互。其他可能的解决方案是什么?希望有人能为我澄清。谢谢,祝你有美好的一天。
2条答案
按热度按时间ifsvaxew1#
问题是您从列表中随机选择了一个选项,但没有正确使用它。
random.choice(element)
的用法不正确。您可以使用下面的代码作为您所面临问题的参考。这里
//tbody[@role='rowgroup']/tr[@role='row']/td[2]/a
是包含所有用户名字段(加上一些其他元素)的表格单元格的xpath在这第一行中,它将首先从你的列表中创建一个带有随机值的变量。2然后它将把带有随机选项的变量传递到表格单元格的xpath中,并单击它。3一个带有“阻止权限”的新对话框将打开
gjmwrych2#
要单击
table
上列出的特定username
,您需要使用唯一的xpath
进行单击。登录后添加此代码。