我的ruby watir脚本有问题。
我想点击所有下一页直到最后一页,然后输入一些名字和姓氏。我知道最后一个“下一个”链接被另外一个类“禁用”stop = b.link(class: 'next-pagination page-link disabled')
调用。
我尝试循环,直到达到这个类break if stop.exists?
loop do
link = b.link(class: 'next-pagination page-link')
name_array = b.divs(class: 'name-and-badge-container').map { |e| e.div(class:'name-container').link(class: 'name-link profile-link').text.split("\n") }
puts name_array
stop = b.link(class: 'next-pagination page-link disabled')
break if stop.exists?
link.click
end
我有这个错误:
此代码在等待Element存在的默认超时期间休眠。如果测试仍在通过,请考虑使用Element#exists?而不是拯救UnknownObjectException /Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/elements/element.rb:496:in
rescue in wait_for_exists': timed out after 30 seconds, waiting for #<Watir::Div: located: false; {:class=>"name-and-badge-container", :tag_name=>"div", :index=>13}> to be located (Watir::Exception::UnknownObjectException) from /Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/elements/element.rb:486:in
wait_for_exists' 来自/Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/elements/element.rb:487:in {{1} } wait_for_exists' 来自/Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/elements/element.rb:639:in {{1} }文本' 来自/Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:inwait_for_exists' from /Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/elements/element.rb:487:in
每个' 来自/Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/element_collection.rb:28:inelement_call' from /Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/elements/element.rb:91:in
地图“ 来自/Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:inblock (2 levels) in start' from /Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/element_collection.rb:28:in
loop' 来自/Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:ineach' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:in
'
点击下一页,但找不到下一个禁用按钮。
答案 0 :(得分:0)
使用文本找到该元素
b.span(text: 'Suivant').click
您不必使用父链接,然后像b.link()。span()那样跨度,而不是按照我解释的方式直接定位。