selenium.common.exceptions.ElementClickInterceptedException:消息:元素 <a class="more" 在该点不可点击
selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a class="more" is not clickable at point
我目前正在开发一个 Python 项目,其中脚本访问网站 (https://service.berlin.de/dienstleistung/120686/),然后单击 link“Termin berlinweit suchen und buchen”。
我试过:
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:\Users\Me\AppData\Local\Programs\Python\Python37\geckodriver.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 共 link:
<a 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" 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 click 因为它不测试 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()
我目前正在开发一个 Python 项目,其中脚本访问网站 (https://service.berlin.de/dienstleistung/120686/),然后单击 link“Termin berlinweit suchen und buchen”。
我试过:
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:\Users\Me\AppData\Local\Programs\Python\Python37\geckodriver.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 共 link:
<a 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" 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 click 因为它不测试 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()