我的 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#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: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
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: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
text' 来自 /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
每个'来自 /Users/vincentcheloudiakoff/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/watir-6.2.1/lib/watir/element_collection.rb:28:ineach' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:in
map' 来自 /用户/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:inblock in start' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:in
loop' 来自 /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:instart' from start.rb:3:in
'
它点击下一页,但没有找到下一个禁用的按钮。