我在我的紅寶石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: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: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 /' from /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
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:inblock in start' from /Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:in
循環 ' 從/Users/vincentcheloudiakoff/Travail/Automation/lib/linkedin.rb:22:instart' from start.rb:3:in
'
它點擊下一頁,但沒有找到下一個禁用的按鈕。
你能提供html部分嗎? ,我可能會找到更好的方法來找到該鏈接。代碼中的問題是,它沒有定位該元素。 – RAJ
是,HTML部分是: Suivant 這是最後的「下一個」鏈接 –
你爲什麼不找到使用文本元素的HTML部分?它會工作。 – RAJ