为了账号安全,请及时绑定邮箱和手机立即绑定

Selenium Python无法模拟鼠标点击

Selenium Python无法模拟鼠标点击

哔哔one 2022-05-22 16:58:56
我想模拟使用 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 回答

?
梦里花落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



查看完整回答
反对 回复 2022-05-22
  • 1 回答
  • 0 关注
  • 202 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信