![](/img/trans.png)
[英]How to click on an element that is not a button using Selenium in 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.