[英]python selenium: element click intercepted:
I'm trying to click via find_element_by_xpath() as i did it always.我试图通过 find_element_by_xpath() 点击,因为我总是这样做。 In the case below, there is an error when try to click this element.
在以下情况下,尝试单击此元素时会出错。 I'm quite new with selenium and researched already.
我对 selenium 很陌生,并且已经研究过了。 It seems that i have to click on specific coordination.
看来我必须点击特定的协调。 Do you have any idea how to solve this problem?
你知道如何解决这个问题吗? i'm struggling for quite a while.
我挣扎了好一阵子。
section of HTML code: HTML代码部分:
<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">
my Code:我的代码:
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()
error message:错误信息:
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">
on other treads at stackoverflow, people suggest to use the following line.在stackoverflow的其他方面,人们建议使用以下行。 If i try, there is a TimeoutExeption.
如果我尝试,有一个 TimeoutExeption。
WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.XPATH, "//map[@id='clickareasVillage']/area[2]")))
Try using javascript尝试使用 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)
There may be something which could be preventing click on the element, check if any pop-up occuring.可能有一些东西可能会阻止点击元素,检查是否出现任何弹出窗口。
As said above, usually when you encounter this error it's because a pop-up or an invisible overlay is preventing the driver from clicking on your element.如上所述,通常当您遇到此错误时,是因为弹出窗口或不可见的覆盖阻止驱动程序单击您的元素。
You said that JS clicking wasn't working either so i'm going to give you 2 quick workarounds that you can try:您说 JS 单击也不起作用,所以我将为您提供 2 个快速解决方法,您可以尝试:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(element).click().perform()
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
Let me know if that helped you.让我知道这是否对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.