selenium.common.exceptions.ElementClickInterceptedException: 消息:元素<a class= "more"在点上不可点击



我目前正在开发一个Python项目,其中脚本访问网站(https://service.berlin.de/dienstleistung/120686/),然后单击链接";术语是这样的;。

我试过:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox(executable_path=r'C:UsersMeAppDataLocalProgramsPythonPython37geckodriver.exe')
driver.get("https://service.berlin.de/dienstleistung/120686/")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[4]/div[3]/div[1]/div[2]/div[9]/div[1]/p[1]/a[1]"))).click()

链接的HTML:

<a href="https://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&amp;anliegen[]=120686&amp;dienstleisterlist=122210,122217,327316,122219,327312,122227,122231,327346,122243,327348,122252,329742,122260,329745,122262,329748,122254,329751,122271,327278,122273,327274,122277,327276,122280,327294,122282,327290,122284,327292,327539,122291,327270,122285,327266,122286,327264,122296,327268,150230,329760,122301,327282,122297,327286,122294,327284,122312,329763,122304,327330,122311,327334,122309,327332,122281,327352,122279,329772,122276,327324,122274,327326,122267,329766,122246,327318,122251,327320,122257,327322,122208,327298,122226,327300&amp;herkunft=http%3A%2F%2Fservice.berlin.de%2Fdienstleistung%2F120686%2F" rel="nofollow" class="more"> Termin berlinweit suchen und buchen</a>

错误:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a class="more" href="https://service.berlin.de/terminvereinbarung/termin/tag.php?termin=1&anliegen[]=120686&dienstleisterlist=122210,122217,327316,122219,327312,122227,122231,327346,122243,327348,122252,329742,122260,329745,122262,329748,122254,329751,122271,327278,122273,327274,122277,327276,122280,327294,122282,327290,122284,327292,327539,122291,327270,122285,327266,122286,327264,122296,327268,150230,329760,122301,327282,122297,327286,122294,327284,122312,329763,122304,327330,122311,327334,122309,327332,122281,327352,122279,329772,122276,327324,122274,327326,122267,329766,122246,327318,122251,327320,122257,327322,122208,327298,122226,327300&herkunft=http%3A%2F%2Fservice.berlin.de%2Fdienstleistung%2F120686%2F"> is not clickable at point (471,646) because another element <div id="feedback-footer"> obscures it

这意味着存在一个覆盖,您可以只调用元素上的单击或处理覆盖元素。

a=WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "/html[1]/body[1]/div[1]/div[2]/div[1]/div[1]/div[1]/div[4]/div[3]/div[1]/div[2]/div[9]/div[1]/p[1]/a[1]")))
driver.execute_script("arguments[0].click();", a)

您可以使用linktext而不是绝对的xpath:

错误是因为元素并没有滚动到视图中,添加下面的代码,它就会正常工作。

不要使用javascript点击,因为它不是测试UI而是跳过UI组件

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Termin berlinweit suchen und buchen"))).location_once_scrolled_into_view
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Termin berlinweit suchen und buchen"))).click()

最新更新