python selenium: element click intercepted:



我试图通过find_element_by_xpath()点击,因为我总是这样做。在下面的示例中,尝试单击此元素时会出现错误。我对硒很陌生,已经研究过了。看来我得点击具体的协调了。你知道如何解决这个问题吗?我挣扎了好长一段时间。

部分:

<map ng-if="!enableSvgHighlighting" id="clickareasVillage" name="clickareasVillage" 
ng-show="areas.village.length > 0" class="">
<area ng-repeat="a in areas.village" location-id="32" on-pointer-over="highlightStart(32)" on-
pointer-out="highlightStop(32)" clickable="openBuildingDialog(32)" tg-
coords="758,341,758,342,761,343,763,344,767,345,769" 
coords="758,341,758,342,761,343,763,344,767,345,769" 
shape="poly" building-positioner="32" class="clickable">

我代码:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//map[@id='clickareasVillage']/area[2]")))

ele1=driver.find_element_by_xpath("//map[@id='clickareasVillage']/area[2]")
ele1.click()

错误信息:

ElementClickInterceptedException: element click intercepted: Element 
<area ng-repeat="a in areas.village" location-id="32" 
on-pointer-over="highlightStart(32)" on-pointer-out="highlightStop(32)" clickable="openBuildingDialog(32)" 
tg-coords="758,341,758,342,761,343,763,344,767,345,769" coords="758,341,758,342,761,343,763,344,767,345,769" 
shape="poly" building-positioner="32" 
class="clickable"> is not clickable at point (391, 477). 
Other element would receive the click: <img ng-if="!enableSvgHighlighting" 
ng-show="areas.village.length > 0" class="clickareas" src="layout/images/x.gif" usemap="#clickareasVillage" data-cmp-info="9">

在stackoverflow的其他线程上,人们建议使用以下行。如果我尝试,会有一个timeoutexception。

WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.XPATH, "//map[@id='clickareasVillage']/area[2]")))

如上所述,当您遇到此错误时,通常是因为弹出窗口或不可见的覆盖层阻止驱动程序单击您的元素。

你说JS点击不工作,所以我要给你2个快速的解决方案,你可以尝试:

  1. ActionChains来移动和点击你的元素:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(element).click().perform()
  1. 使用ActionChains发送密钥
from selenium.webdriver.common.action_chains import ActionChains
for i in range(#determine how much time):
ActionChains(driver).send_keys(Keys.TAB).perform() #tab until element is selected
ActionChains(driver).send_keys(Keys.ENTER).perform() #press enter to "click" on it

让我知道这是否对你有帮助。

尝试使用javascript

element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//map[@id='clickareasVillage']/area[2]")))

driver.execute_script("arguments[0].click();", element)

可能有什么东西可以阻止点击元素,检查是否有弹出窗口。

最新更新