2017-06-13 65 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()。跨距(),而不是你可以直接定位跨度我有辦法解釋。

相關問題