Ruby 处理元素在点(x,y)处不可单击。其他元素将收到点击:与水豚,红宝石,Webdriver

Ruby 处理元素在点(x,y)处不可单击。其他元素将收到点击:与水豚,红宝石,Webdriver,ruby,rspec,cucumber,capybara,selenium-chromedriver,Ruby,Rspec,Cucumber,Capybara,Selenium Chromedriver,我正在编写一个UI测试,它将转到文章列表并选择load_more按钮,直到不再可用为止(因为所有文章都已加载)。问题是按钮此时已被隐藏,而不是被删除,并返回此错误 Selenium::WebDriver::Error::UnknownError: unknown error: Element <div class="">...</div> is not clickable at point (x, y). Other element would receive the

我正在编写一个UI测试,它将转到文章列表并选择load_more按钮,直到不再可用为止(因为所有文章都已加载)。问题是按钮此时已被隐藏,而不是被删除,并返回此错误

Selenium::WebDriver::Error::UnknownError: unknown error: Element <div 
class="">...</div> is not clickable at point (x, y). Other element 
would receive the click: <div class="" id="" data-module-name="">... 
</div>

(Session info: chrome=65.0.3325.181)
(Driver info: chromedriver=2.36.540469 
ruby-2.5.1/gems/selenium-webdriver 
3.11.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok'

问题是我如何告诉Selenium这是可以的并且不会出错,这样我就可以在我的测试用例(cucumber)中继续下一步了。我意识到循环类型的选择可能也不正确,所以也可以随意提出修改建议。

首先,正如Rajagopalan所指出的,您得到的错误不是您的元素不可见(如CSS隐藏),而是它与另一个元素重叠。您可以调用
save_和\u open_屏幕截图
,查看哪个元素与按钮重叠(可能是固定的页脚,等等?)。确保您已将窗口大小设置得足够大,以免元素无意中重叠,并确保您正在运行最新版本的Capybara,因为它试图在selenium中通过将重叠元素滚动到视图中(如果可能)来处理重叠元素

第二,你问题中的循环没有太多意义,因为
while
break
都检查相同的东西。此外,假设“加载更多”按钮正在通过AJAX加载并附加到页面,您可能需要等待新元素加载,然后再检查按钮是否存在(
单击
不会等待操作完成,因为它不知道可以/将触发哪些操作)。然后会变成一个类似的结构

 while page.has_button?('Load More')
   # Get the current number of visible articles
   article_count = page.all('div.article').count # Use whatever selector would match an article in the list
   # click the button
   page.click_button('Load More')
   # ensure more articles have loaded
   expect(page).to have_css('div.article', minimum: article_count + 1)
end

注意:您可能希望将其更改为使用您正在使用的任何页面对象方法(
有加载更多?
等),但一般逻辑应该是正确的

不,您的假设是错误的,当按钮被隐藏时不会发生这个错误,相反,当按钮被其他元素覆盖时会发生这个错误。谢谢-应该更清楚。我的意思是隐藏在隐形的/不可见的,你的隐形是不可见的硒,如果元素出现在页面的底部,它是不可见的,但它不是不可见的硒,硒考虑一些无形的元素存在,但它仍然是隐藏的,但无论如何你的错误,它是不可见的!如果它是不可见的,那么它会抛出错误
元素是不可见的
谢谢你提供的详细信息如果你仍然想点击,你可以在你的selenium代码中注入JavaScript,它不做任何检查,但是你会失去隐式等待的控制。感谢这一点-循环非常有意义。关于第一部分,我们将更深入地研究它,看起来开发团队正在使用一些bootstrap()进行响应性设计。当项目列表用尽时,它们通过添加.d-none来“隐藏”元素。不确定这是否会改变您答案的第一部分,但我认为值得一提,即使只是为了清楚起见。@Suleymahoud假设引导CSS已正确加载
。d-none
display:none
分配给元素,但如果这是您的问题,您应该得到一个
找不到元素的
(或等效项)错误,不是
其他元素将收到单击。这一切都假设无论
方法有什么加载更多的内容,它都会忽略隐藏的元素,
单击
方法是标准的水豚
单击
。基本上,您有一个元素与“按钮”重叠(我假设它实际上是错误的一个div),您需要找出原因(查看屏幕截图)
 while page.has_button?('Load More')
   # Get the current number of visible articles
   article_count = page.all('div.article').count # Use whatever selector would match an article in the list
   # click the button
   page.click_button('Load More')
   # ensure more articles have loaded
   expect(page).to have_css('div.article', minimum: article_count + 1)
end