我在点击以下网站的菜单后尝试选择最新的可用日期:
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/