简体   繁体   English

python selenium:元素点击拦截:

[英]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 个快速解决方法,您可以尝试:

  1. ActionChains to move and click on your element: ActionChains 移动并单击您的元素:
from selenium.webdriver.common.action_chains import ActionChains

ActionChains(driver).move_to_element(element).click().perform()
  1. Send keys using ActionChains使用 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

Let me know if that helped you.让我知道这是否对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Selenium 元素点击拦截 - Python Selenium element click intercepted 元素点击截获硒 - Element click intercepted selenium 元素点击被拦截(点击工作完美)(硒python)(弹出) - element click intercepted (click work perfectly)(selenium python)(popup) ElementClickInterceptedException: 消息: 元素点击被拦截: <label>Selenium 和 Python 无法点击</label>元素 - ElementClickInterceptedException: Message: element click intercepted: Element <label> is not clickable with Selenium and Python 如果检查元素点击的语句不会被拦截(Python Selenium) - If statement to check element click won't be intercepted (Python Selenium) Selenium - 元素点击被拦截:元素在点不可点击 - Selenium - element click intercepted: Element is not clickable at point selenium.common.exceptions.ElementClickInterceptedException:消息:元素点击被拦截:元素不可点击 Selenium 和 Python - selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python ElementClickInterceptedException: 元素点击被拦截。 其他元素会收到点击:Selenium Python - ElementClickInterceptedException: element click intercepted. Other element would receive the click: Selenium Python selenium.common.exceptions.ElementClickInterceptedException:消息:使用 Selenium 单击单选按钮时元素单击被截获错误 - selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted error clicking on a radiobutton using Selenium Python ElementClickInterceptedException:消息:元素单击拦截元素不可单击错误单击使用 Selenium 和 Python 的单选按钮 - ElementClickInterceptedException: Message: element click intercepted Element is not clickable error clicking a radio button using Selenium and Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM