Python Selenium 调试:元素在 (X,Y) 点不可点击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37879010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium-Debugging: Element is not clickable at point (X,Y)
提问by parik
I try to scrape this siteby Selenium.
我尝试通过 Selenium抓取这个网站。
I want to click in "Next Page" buttom, for this I do:
我想点击“下一页”按钮,为此我这样做:
driver.find_element_by_class_name('pagination-r').click()
it works for many pages but not for all, I got this error
它适用于许多页面但不适用于所有页面,我收到此错误
WebDriverException: Message: Element is not clickable at point (918, 13). Other element would receive the click: <div class="linkAuchan"></div>
always for this page
总是为这个页面
I read this question
我读了这个问题
and I tried this
我试过这个
driver.implicitly_wait(10)
el = driver.find_element_by_class_name('pagination-r')
action = webdriver.common.action_chains.ActionChains(driver)
action.move_to_element_with_offset(el, 918, 13)
action.click()
action.perform()
but I got the same error
但我遇到了同样的错误
回答by RemcoW
Another element is covering the element you are trying to click. You could use execute_script()
to click on this.
另一个元素覆盖了您尝试单击的元素。你可以execute_script()
用来点击这个。
element = driver.find_element_by_class_name('pagination-r')
driver.execute_script("arguments[0].click();", element)
回答by Deepak Garud
I had a similar issue where using ActionChains was not solving my error: WebDriverException: Message: unknown error: Element is not clickable at point (5 74, 892)
我有一个类似的问题,即使用 ActionChains 无法解决我的错误:WebDriverException: Message: unknown error: Element is not clickable at point (5 74, 892)
I found a nice solution if you dont want to use execute_script:
如果您不想使用execute_script,我找到了一个不错的解决方案:
from selenium.webdriver.common.keys import Keys #need to send keystrokes
inputElement = self.driver.find_element_by_name('checkout')
inputElement.send_keys("\n") #send enter for links, buttons
or
或者
inputElement.send_keys(Keys.SPACE) #for checkbox etc
回答by Rakesh Raut
Use explicit wait instead of implicit.
使用显式等待而不是隐式等待。
new WebDriverWait(TestingSession.Browser.WebDriver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists((By.ClassName("pagination-r'"))));
回答by quickauto
If you are receiving an element not clickable
error, even after using wait on the element, try one of these workarounds:
如果您收到element not clickable
错误消息,即使在对元素使用 wait 之后,请尝试以下解决方法之一:
- Use
Action
to move to the location ofelement
and then runperform
onaction
- 使用
Action
移动到的位置element
,然后运行perform
上action
WebElement element = driver.findElement(By("element_path"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().perform();`
- Check for an overlay or spinner on the
element
andwait
for its invisibility
- 检查的覆盖或微调
element
,并wait
为它的隐蔽性
By spinnerimg = By.id("spinner ID");
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
wait.until(ExpectedConditions.invisibilityOfElementLocated(spinnerimg ));
Hope this helps
希望这可以帮助
回答by Chetan Kolhe
I have written logic to handle these type of exception .
我已经编写了处理这些类型异常的逻辑。
def find_element_click(self, by, expression, search_window=None, timeout=32, ignore_exception=[],
poll_frequency=4):
"""It find the element and click then handle all type of exception during click
:param poll_frequency:
:param by:
:param expression:
:param timeout:
:param ignore_exception:
:return:
"""
ignore_exception.append(NoSuchElementException)
if search_window is None:
search_window = self.driver
end_time = time.time() + timeout
while True:
try:
web_element = search_window.find_element(by=by, value=expression)
web_element.click()
return True
except tuple(ignore_exception) as e:
self.logger.debug(str(e))
if time.time() > end_time:
self.logger.exception(e)
time.sleep(poll_frequency)
break
except Exception as e:
raise
self.logger.debug("Not able to click the element")
return False