我想模拟使用 Python/Selenium 单击网页菜单项,但收到以下错误消息:ElementNotVisibleException: Cannot click on element这是我的代码:driver.switch_to.default_content()frame = driver.find_element_by_css_selector("frame[name='MenuFrame']")driver.switch_to.frame(frame)driver.implicitly_wait(15)driver.find_element_by_xpath("//*[contains(@url,'History')]").click()网页元素如下所示:我想我需要以某种方式访问元素中的 onclick 事件,但无法弄清楚如何做到这一点
1 回答
![?](http://img1.sycdn.imooc.com/545863dc00011d2202200220-100-100.jpg)
梦里花落0921
TA贡献1772条经验 获得超6个赞
我之前发现过通过 Selenium 点击的问题,并通过使用 Javascript 点击元素来解决它。
例如
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(driver, 15)
my_xpath = "//frame[@name='MenuFrame']"
button = driver.find_element_by_xpath("//frame[@name='MenuFrame']]")
wait.until(EC.element_to_be_clickable((By.XPATH, my_xpath))) # wait until it's clickable
driver.execute_script("arguments[0].click();", button) # JS to click the element
添加回答
举报
0/150
提交
取消