单击后从菜单中选择

2024-10-01 02:39:47 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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>

如何消除错误?你知道吗


Tags: fromimportdivhttpdatetimedriverseleniumelement
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)

尝试将元素滚动到视图中:

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.

在大多数情况下,问题是元素在页面的某个地方,但它不在活动窗口中,因此selenium无法对其采取任何操作。你知道吗

相关问题 更多 >