单击Selenium Python后从菜单中选择

时间:2019-06-12 21:04:04

标签: 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 个答案:

答案 0 :(得分:2)

有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)

答案 1 :(得分:1)

尝试将元素滚动到视图中

xml_item = self.driver.find_element_by_name('//*[@id="iform_ausweisung_szm"]/table/tbody/tr/td[3]/div/select')
driver.execute_script("arguments[0].scrollIntoView(false);", xml_item)
xml_item.click() # Or any other action item.

在大多数情况下,问题在于该元素在页面上的某个位置,但是它不在硒的活动窗口中,因此硒无法对其采取任何措施。