单击所有不同的下一页进入循环,直到最后一页与 Watir gem

Click to all different next pages into a loop until the last page with Watir gem

我的 ruby watir 脚本有问题。

我想点击所有下一页直到最后一页,然后输入一些名字和姓氏。我知道最后一个 "next" link 被调用了一个 class "disabled" stop = b.link(class: 'next-pagination page-link disabled')。 我尝试循环直到达到 classes 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

我有这个错误:

This code has slept for the duration of the default timeout waiting for an Element to exist. If the test is still passing, consider using Element#exists? instead of rescuing 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: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' 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: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:639:in element_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:intext' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:in block (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:ineach' 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 each' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:inmap' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:in block in start' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:inloop' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:in start' from start.rb:3:in'

它点击了下一页,但没有找到下一个禁用按钮。

使用文本定位该元素

b.span(text: 'Suivant').click

您不必使用父级 link 然后像 b.link().span() 这样的跨度,而是可以按照我解释的方式直接定位跨度。