我的网页中有一个“ onclick”元素,其HTML内容如下:
<a href="#" onclick="blah.submit()">Text 1</a>
我正在尝试使用硒单击此元素。我尝试了以下代码(包括隐式等待)
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(webpage);
driver.implicitly_wait(5)
driver.find_element_by_xpath("//a[@onclick='blah.submit()']").click()
但是,它返回了NoSuchElementException
NoSuchElementException: Message: no such element: Unable to locate element:
{"method":"xpath","selector":"//a[@onclick='blah.submit()']"}
然后我尝试使用WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get(webpage);
button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH,
"//a[@onclick='blah.submit()']")))
button.click()
但是,它仍然无法正常工作并返回以下错误:
TimeoutException: Message:
有人知道出什么事了吗?预先感谢。