我有一个HTML页面,如下所示:
<div>
<div class="drawer">
<div class="fill-layout">
<div class="drawer-body">
<div class="help-resources">
<div>
<ul class="help-resources-links">
<li><a href="/url1"><i class="book"></i>Book</a></li>
<li><a href="/url2"><i class="document"></i>Document</a></li>
<li><a href="/url3"><i class="form"></i>Form</a></li>
我想点击
<li><a href="/url1"><i class="book"></i>Book</a></li>
并查看是否在指定的文件路径中下载了书籍
我的代码如下:
require 'watir'
prefs = {
download: {
prompt_for_download: true,
default_directory: '/Users/user.name/Downloads/watir-downloads'
}
}
browser = Watir::Browser.start 'https://admin:password@website.com'
我尝试了很少的方法,但它们都不起作用
1. browser.div(:class, "help-resources").link(:text, "Book").click
Output :
Traceback (most recent call last):
10: from download.rb:18:in `<main>'
9: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/elements/element.rb:125:in `click'
8: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/elements/element.rb:657:in `element_call'
7: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/elements/element.rb:661:in `rescue in element_call'
6: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/elements/element.rb:661:in `count'
5: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/element_collection.rb:29:in `each'
4: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/element_collection.rb:70:in `to_a'
3: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/element_collection.rb:124:in `elements'
2: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/elements/element.rb:603:in `ensure_context'
1: from /usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/elements/element.rb:578:in `assert_exists'
/usr/local/lib/ruby/gems/2.5.0/gems/watir-6.10.3/lib/watir/elements/element.rb:583:in `assert_element_found':
unable to locate element: #<Watir::Div: located: false; {:class=>"help-resources", :tag_name=>"div"}> (Watir::Exception::UnknownObjectException)
2. browser.ul(:class, 'help-resources-links').child.a(:text, 'Book').click
Output :
assert_element_found': unable to locate element: #<Watir::UList: located: false; {:class=>"help-resources", :tag_name=>"ul"}> (Watir::Exception::UnknownObjectException)
3. if browser.div(:class, 'help-resources').child.a(:text, 'Book').exists?
puts "in if block"
browser.div(:class, 'help-resources'').a(:text, 'Book').click
end
Doesn't print "in if block" on terminal , code executes to completion