繁体   English   中英

使用python硒中的按钮单击元素问题

[英]Button Click element issue in selenium using python

我正在尝试单击网页上的按钮(名称命令页面),但我无法这样做。 我在 python 中使用硒

代码:

wait= WebDriverWait(driver,20)
command_page = wait.until(EC.element_to_be_clickable((By.ID,"Button_ID")))
command_page.click()

我也尝试过按类名,但我无法单击该元素。 请帮我解决这个问题。

请尝试以下解决方案:

WebDriverWait(driver, 20)
both_button=wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'Command Page')]")))
both_button.click()

作为替代方案,如果 Selenium click()方法没有在没有任何异常的情况下触发操作,则您可以使用 JavascriptExecutor 来执行单击某个元素。

element = driver.find_element_by_id("etoolbar_toolbarSection_newcommandpagebtn_id")
driver.execute_script("arguments[0].click();", element)

我试过这个,似乎有效

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("file://c:/cygwin64/home/das2/abcd.html")
element = driver.find_element_by_id("etoolbar_toolbarSection_newcommandpagebtn_id")
element.click()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM