python selenium: 元素点击拦截:
python selenium: element click intercepted:
我正尝试像往常一样通过 find_element_by_xpath() 单击。在下面的情况下,尝试单击此元素时会出错。我对硒很陌生并且已经研究过了。看来要点具体协调了。你知道如何解决这个问题吗?我挣扎了好久
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">
我的代码:
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">
在 Whosebug 的其他方面,人们建议使用以下行。如果我尝试,就会出现 TimeoutExeption。
WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.XPATH, "//map[@id='clickareasVillage']/area[2]")))
尝试使用 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)
可能有一些东西阻止了点击元素,检查是否有弹出窗口。
如上所述,当您遇到此错误时,通常是因为弹出窗口或不可见的叠加层阻止驱动程序单击您的元素。
你说 JS 点击也不起作用,所以我会给你 2 个你可以尝试的快速解决方法:
- ActionChains 移动并点击您的元素:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(element).click().perform()
- 使用 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
如果对你有帮助,请告诉我。
我正尝试像往常一样通过 find_element_by_xpath() 单击。在下面的情况下,尝试单击此元素时会出错。我对硒很陌生并且已经研究过了。看来要点具体协调了。你知道如何解决这个问题吗?我挣扎了好久
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">
我的代码:
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">
在 Whosebug 的其他方面,人们建议使用以下行。如果我尝试,就会出现 TimeoutExeption。
WebDriverWait(driver, 20).until(EC.invisibility_of_element((By.XPATH, "//map[@id='clickareasVillage']/area[2]")))
尝试使用 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)
可能有一些东西阻止了点击元素,检查是否有弹出窗口。
如上所述,当您遇到此错误时,通常是因为弹出窗口或不可见的叠加层阻止驱动程序单击您的元素。
你说 JS 点击也不起作用,所以我会给你 2 个你可以尝试的快速解决方法:
- ActionChains 移动并点击您的元素:
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(element).click().perform()
- 使用 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
如果对你有帮助,请告诉我。