python - 单击selenium python后从菜单中选择

标签 python selenium selenium-webdriver

我在点击以下网站的菜单后尝试选择最新的可用日期:

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from _datetime import datetime
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys

url = "http://ausweisung.ivw-online.de/index.php?i=1161&a=o52802"
driver = webdriver.Chrome(executable_path = driver_path, chrome_options=chromeOptions)
driver.get("http://ausweisung.ivw-online.de/" + Link)
time.sleep(random.randint(7, 10))
driver.find_element_by_xpath('//*[@id="iform_ausweisung_szm"]/table/tbody/tr/td[3]/div/select').click()

但是,即使在第一步我也会收到以下错误:

ElementClickInterceptedException: element click intercepted: Element <select name="a" class="inaktiv" onchange="document.getElementById('iform_ausweisung_szm').submit();">...</select> is not clickable at point (875, 31). Other element would receive the click: <div class="bread">...</div>

如何消除错误?

最佳答案

这里有 2 个选项来处理这个问题。

选项 1:滚动到选择,然后单击

 listEle = driver.find_element_by_xpath('//*[@id="iform_ausweisung_szm"]/table/tbody/tr/td[3]/div/select')
 listEle.location_once_scrolled_into_view # this will scroll to the element
 #click on the element
 listEle.click()

选项 2:使用 javascript

 listEle = driver.find_element_by_xpath('//*[@id="iform_ausweisung_szm"]/table/tbody/tr/td[3]/div/select')
 #click using javascript
 driver.execute_script("arguments[0].click()",listEle)

关于python - 单击selenium python后从菜单中选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56570333/

相关文章:

python - 如何获取Python中动态定义函数的源代码?

python - 用于管理线程的替代 python 库

c# - 在特定的 IWebElement 上使用 webdriverwait

internet-explorer-9 - Selenium 2.0b3 IE WebDriver,点击不触发

java - Selenium 在 Firefox 浏览器窗口中运行一些测试时出现 "Can' t 查找配置文件目录错误

python - 谷歌CP : Creating Client() object locally

python - 访问多处理映射中的共享数据帧

java - 是否可以在不使用 Selenium Webdriver Java 中的 driver.switchTo().frame ("frameName"的情况下切换到框架中的元素?

python - 使用 selenium 和 phantomJS 更改 "user-agent" header

c# - 如何为 Selenium 添加自定义 ExpectedConditions?