因为我找不到我想要的答案。 我正在尝试自动点击红色按钮。
在此处输入图像说明
我自动完成了对这个站点的登录(不知道是哪个站点),并且添加了等待函数,但是,不管是复制完整的xpath,选择器还是复制函数在“Inspect Element”中给我的其他选项,我都无法让Python执行click the button.(可能是因为按钮图像用作覆盖--可能是错误的,但在我看来是这样)。
这是我使用的代码:
`从selenium导入webdriver导入时间
驱动程序=webdriver.chrome(“C:\users\xxxxxxxxxxx\desktop\chromedriver_Win32\chromedriver.exe”)driver.get(“xxxxxxxxxxx”)
driver.find_element_by_id(“e_user”)。send_keys(“xxxxxxxxxxx”)driver.find_element_by_id(“e_pass”)。send_keys(“xxxxxxxxxxx”)driver.find_element_by_xpath(“/html/body/div[4]/table/Tbody/Tr[5]/Td2/input”)。单击()time.sleep(5)
driver.find_element_by_xpath(“//button[@onclick=”btn_click(this,'btn_2_1')“]”).click()`
粗体命令不起作用。 其他的都没问题。
我尝试了通过xpath,文本名称(pocetak prisustva na radu)和其他几个selenium通过id查找元素选项来查找元素,但没有成功。
我想最好的方法是找到onclick元素并点击它,但是我在代码编程方面是个新手,所以如果有人能帮助我,我会非常感激。 您在那里看到的每个按钮都有一个唯一的onlick名称。 我将添加更多的图片,因为它们可能有助于找到解决方案。
提前谢谢你。
真诚的,吉奇
在此处输入图像说明
您可以尝试使用ActionChains元素,这是您在xpath中找到的元素
from selenium.webdriver import ActionChains
actions = ActionChains(browser)
actions.move_to_element(element).perform()
actions.click().perform()
您可以在以下网址阅读有关ActionChains的更多信息:https://www.selenium.dev/selenium/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html