-1

我的 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:inwait_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 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' 来自/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' 来自 /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:in each' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:inmap' 来自 /用户/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:in block in start' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:inloop' 来自 /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:in start' from start.rb:3:in'

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

4

1 回答 1

0

使用文本定位该元素

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

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

于 2017-06-13T12:35:08.280 回答