问题描述
限时送ChatGPT账号..我正在尝试使用最新的 Watir-Webdriver 0.9.1、Selenium-Webdriver 2.53.0 和 Chrome 扩展 2.21 在 Ruby 中自动测试em>.然而,我正在测试的网站在顶部有静态页眉,有时在底部有静态页脚.因此,由于 Watir 在单击之前自动将元素滚动到视图中,因此元素会隐藏在静态页眉或静态页脚下.我不想将 desired_capabitlites (ElementScrollBehavior)
设置为 1
或 0
因为我正在测试的网站可以同时拥有 - 静态页眉或静态页脚或两者.
I am trying to automate tests in Ruby using the latest Watir-Webdriver 0.9.1, Selenium-Webdriver 2.53.0 and Chrome extension 2.21. However the website that I am testing has static headers at the top or sometimes static footers at the bottom. Hence since Watir auto-scrolls an element into view before clicking, the elements get hidden under the static header or the static footer. I do not want to set desired_capabitlites (ElementScrollBehavior)
to 1
or 0
as the websites I am testing can have both - static header or static footer or both.
因此问题是:
1) 为什么 Watir 会抛出异常 Element not clickable
即使元素可见且存在?请参阅 ruby 代码(我选择了一个随机的公司网站作为示例)和下面的结果.
2) 如何在不求助于 ElementScrollBehaviour 的情况下解决此问题?
Hence the question are:
1) Why does Watir throw an exception Element not clickable
even when the element is visible and present? See ruby code ( I have picked a random company website for an example) and the results below.
2) How can I resolve this without resorting to ElementScrollBehaviour?
require 'watir-webdriver'
browser = Watir::Browser.new :chrome
begin
# Step 1
browser.goto "shop.coles.au/online/mobile/national"
# Step 2 - click on 'Full Website' link at the bottom
link = browser.link(text: "Full website")
#check if link exists, present and visible?
puts link.exists?
puts link.present?
puts link.visible?
#click on link
link.click
rescue => e
puts e.inspect
ensure
sleep 5
end
puts browser.url
browser.close
结果:
$ ruby link_not_clickable.rb
true
true
true
Selenium::WebDriver::Error::UnknownError: unknown error: Element is not clickable at point (460, 1295). Other element would receive the click: div class="shoppingFooter"...div
(Session info: chrome=50.0.2661.75)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Mac OS X 10.10.5 x86_64)>
http://shop.coles.au/online/mobile/national
谢谢!
推荐答案
您可以单击任何元素而不使其可见.看看这个:
You can do a click at any element without getting it visible. Check this out:
link.fire_event('click')
但是这是非常非常非常不好的决定,因为它会点击元素,即使它实际上并不可见,或者在不可能点击它的情况下(因为粘性损坏例如页脚).
BUT It is very very very not good decision as far as it will click the element even if it is not actually visible or in case when it is just impossible to click it (because of broken sticky footer for example).
这就是为什么最好等待傻瓜,滚动页面然后点击像:
That's why much better to wait the fooler, scroll the page and then click like:
browser.div(id: "footerMessageArea").wait_until_present
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
link.click
这篇关于即使元素可见,Watir-webdriver 也会抛出“不可点击"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论