Can not click on a Element: ElementClickInterceptedException in Splinter / Selenium

喜你入骨 提交于 2019-12-18 05:46:06

问题


I'm trying to scrape a page, but I sometimes have trouble clicking a link/button.

When the web page loads, then the "loadingWhiteBox" will appear first and then disappear after a few seconds (but it will remain in the HTML code) as long as the box is appears on the website, I can not click on the link and get following error message:

selenium.common.exceptions.ElementClickInterceptedException: Message: 
Element <span class="taLnk ulBlueLinks"> is not clickable at point 
(318.3000030517578,661.7999877929688) because another element <div 
class="loadingWhiteBox"> obscures it

Is there any way to work around this? I've already tried working with the following command:

driver.is_element_present_by_css('div[class*="loadingWhiteBox"]')

But the element is present even when it's not active.


回答1:


You can try the below 2 methods to click on element.

element = driver.find_element_by_css('div[class*="loadingWhiteBox"]')
driver.execute_script("arguments[0].click();", element)

element = driver.find_element_by_css('div[class*="loadingWhiteBox"]')
webdriver.ActionChains(driver).move_to_element(element ).click(element ).perform()

hope this will work.




回答2:


You can wait until the element gone,

    WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("loadingWhiteBox")));



回答3:


The error appears because another element with same class or with same xpath/css appears on the screen.

Try giving some wait methods until the element appears such Thread.sleep(), wait().



来源:https://stackoverflow.com/questions/48665001/can-not-click-on-a-element-elementclickinterceptedexception-in-splinter-selen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!