2017-06-13 66 views
-1

我在我的红宝石watir脚本有问题。点击所有不同的下一页成循环,直到与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#存在?而不是拯救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' 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: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: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:in text /' 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:in each' 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:在each' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:in映射' 从/Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:24:in block in start' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:in循环 ' 从/Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:in start' from start.rb:3:in'

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

+0

你能提供html部分吗? ,我可能会找到更好的方法来找到该链接。代码中的问题是,它没有定位该元素。 – RAJ

+0

是,HTML部分是: Suivant 这是最后的“下一个”链接 –

+0

你为什么不找到使用文本元素的HTML部分?它会工作。 – RAJ

回答

0

使用文本来定位元素

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

您不必使用父链接,然后跨越像b.link()。跨距(),而不是你可以直接定位跨度我有办法解释。

相关问题