在我的测试中,我试图点击etsy.com,进行搜索,点击结果,然后将项目添加到我的购物车.我可以做任何事情,直到我尝试点击"添加到购物车"按钮.下面的代码实际上在IRB中工作,所以我知道我的定位器是可靠的,但是当我运行测试时,我得到一个元素在点错误时无法点击
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/selenium-webdriver-3.6.0/lib/selenium/webdriver/remote/response.rb:71:in 'assert_ok': unknown error: Element is not clickable at point (930, 586) (Selenium::WebDriver::Error::UnknownError)
(Session info: chrome=61.0.3163.100)
这是我的考试
require 'watir'
# test that a user can search for and add an item to shopping cart
b = Watir::Browser.new :chrome
begin
b.goto "http://etsy.com"
b.text_field(:id => 'search-query').set 'bacon is my spirit animal coaster'
b.button(:value => 'Search').present?
b.button(:value => 'Search').click
b.p(:text => /Bacon Spirit Animal Coaster/).click
b.select_list(:id => 'inventory-variation-select-0').option(:text => 'Single ($8.00)').select
b.button(:text => /Add to cart/).click
if b.text.include?("item in your cart")
puts "Test passed!"
else
puts "Test failed!"
end
ensure
b.close
end
Run Code Online (Sandbox Code Playgroud)
这是按钮的页面HTML.
<button class="btn-transaction" type="submit">
<div class="btn-text">Add to cart</div>
<div class="ui-toolkit">
<div class="btn-spinner spinner spinner-small display-none"></div>
</div>
</button>
Run Code Online (Sandbox Code Playgroud)
根据浏览器宽度(以及可能的其他因素),可能会有添加到购物车按钮上方的对话框.例如,当测试失败时,按钮顶部有一个入门对话框.Chrome会尝试按位置点击.如果另一个元素位于该位置元素的顶部,Chrome将抛出异常.
最简单的解决方案是通过直接触发点击事件来绕过Chrome的检查:
# Watir > 6.8.0:
b.button(:text => /Add to cart/).click! # note the exclamation mark
# Watir < 6.8.0:
b.button(:text => /Add to cart/).fire_event(:onclick)
Run Code Online (Sandbox Code Playgroud)
其他可能有条件的解决方案:
browser.window.maximize.这可以使浮动元件远离按钮.| 归档时间: |
|
| 查看次数: |
912 次 |
| 最近记录: |