调试“元素在点上无法点击”错误

在使用Selenium进行自动化测试时,遇到'Element is not clickable at point'错误,主要出现在Chrome浏览器中。错误表示元素不可点击,而其他元素将接收点击。尝试过的解决方案包括增加偏移量、等待、改变元素定位方式等,但并非所有方法都有效。一种可能的解决办法是直接导航到要点击元素的父级链接的href。
摘要由CSDN通过智能技术生成

本文翻译自:Debugging “Element is not clickable at point” error

I see this only in Chrome. 我只在Chrome中看到这一点。

The full error message reads: 完整的错误消息显示:

"org.openqa.selenium.WebDriverException: Element is not clickable at point (411, 675). Other element would receive the click: ..." “org.openqa.selenium.WebDriverException:元素在点(411,675)处不可点击。其他元素将收到点击:...”

The element that 'would receive the click' is to the side of the element in question, not on top of it and not overlapping it, not moving around the page. “将接收点击”的元素位于相关元素的一侧,而不是位于其上方且不与其重叠,而不是在页面上移动。

I have tried adding an offset, but that does not work either. 我试过添加一个偏移量,但这也不起作用。 The item is on the displayed window without any need for scrolling. 该项目位于显示的窗口上,无需滚动。


#1楼

参考:https://stackoom.com/question/nxsX/调试-元素在点上无法点击-错误


#2楼

There seems to be a bug in chromedriver for that (the problem is that it's marked as won't fix) --> GitHub Link chromedriver中似乎有一个错误(问题是它被标记为无法修复) - > GitHub Link

(place a bounty on FreedomSponsors perhaps?) (也许会给自由赞助商带来赏金?)

There's a workaround suggested at comment #27. 评论#27中提出了一种解决方法。 Maybe it'll work for you. 也许它对你有用。


#3楼

I was facing a similar problem whre i have to check two check boxes one after the other.But i was getting the same above error.hence i added wait in between my steps for checking the checkboxes....its working fine and great.here are the steps:- 我面临一个类似的问题,我必须一个接一个地检查两个复选框。但我得到了相同的上述错误。因此我在我的步骤之间添加等待检查复选框....它的工作正常和伟大。以下是步骤: -

  When I visit /administrator/user_profiles
  And I press xpath link "//*[@id='1']"
  Then I should see "Please wait for a moment..."
  When I wait for 5 seconds
  And I press xpath link "//*[@id='2']"
  Then I should see "Please wait for a moment..."
  When I visit /administrator/user_profiles_updates

#4楼

Apparently this is the result of a "Won't Fix" bug in the Chrome driver binary. 显然,这是Chrome驱动程序二进制文件中“无法修复”错误的结果。

One solution that worked for me (Our Mileage May Vary) can be found in this Google Group discussion, Comment #3: 一个对我有用的解决方案(我们的里程可能会变化)可以在Google Group讨论中找到,评论#3:

https://groups.google.com/forum/?fromgroups=#!topic/selenium-developer-activity/DsZ5wFN52tc https://groups.google.com/forum/?fromgroups=#!topic/selenium-developer-activity/DsZ5wFN52tc

The relevant portion is right here: 相关部分就在这里:

I've since worked around the issue by navigating directly to the href of the parent anchor of the span. 我已经解决了这个问题,直接导航到span的父锚点的href。

driver.Navigate().GoToUrl(driver.FindElement(By.Id(embeddedSpanIdToClick)).FindElement(By.XPath("..")).GetAttribute("href")); 。driver.Navigate()GoToUrl(driver.FindElement(By.Id(embeddedSpanIdToClick))FindElement(By.XPath( “.. ”))的getAttribute(的“ href”));

In my case, I'm using Python, so once I got the desired element, I simply used 就我而言,我正在使用Python,所以一旦我得到了所需的元素,我就会使用它

driver.get(ViewElm.get_attribute('href'))

I would expect this to only work, however, if the element you are trying to click on is a link... 我希望这只能起作用,但是,如果你想点击的元素是一个链接......


#5楼

I had the same problem and it was caused by an id conflict between the div and the link inside the div. 我有同样的问题,它是由div和div内部的链接之间的ID冲突引起的。 So driver was clicking on the div instead of the link that I wanted. 所以司机点击了div而不是我想要的链接。 I changed the div id and it worked properly. 我更改了div id并且它正常工作。

Before: 之前:

<div id="logout"><a id="logout" href="logoutLink">logout</a></div>

After: 后:

<div id="differentId"><a id="logout" href="logoutLink">logout</a></div>

#6楼

I had the same issue, tried all offered solutions but they did not work for me. 我有同样的问题,尝试了所有提供的解决方案,但他们不适合我。 eventually I used this: 最后我用过这个:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("var evt = document.createEvent('MouseEvents');" + "evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);" + "arguments[0].dispatchEvent(evt);", findElement(element));

Hope this helps 希望这可以帮助

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值