Ruby Watir Gem,定时输入表格

时间:2017-03-14 22:39:18

标签: ruby-on-rails ruby web-scraping nokogiri watir

我正在使用Watir,Mechanize和Nokigiri宝石练习网页拼图。

我遇到了Watir脚本的问题。我的计划是通过http://tripadvisor.com/获取航班价格清单。当我运行脚本时,Chrome浏览器会按原样打开,脚本会继续填写表单的第一部分,原点和目标,然后停止。以下是我收到的错误消息:

This code has slept for the duration of the default timeout waiting for an Element to be present. If the test is still passing, consider using Element#exists? instead of rescuing UnknownObjectException
/home/jaffejoe/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/watir-6.2.0/lib/watir/elements/element.rb:515:in `rescue in wait_for_present': element located, but timed out after 30 seconds, waiting for true condition on #<Watir::Input: located: true; {:name=>"rt_leaveday", :tag_name=>"input"}> (Watir::Exception::UnknownObjectException)
    from /home/jaffejoe/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/watir-6.2.0/lib/watir/elements/element.rb:505:in `wait_for_present'
    from /home/jaffejoe/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/watir-6.2.0/lib/watir/elements/element.rb:522:in `wait_for_enabled'
    from /home/jaffejoe/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/watir-6.2.0/lib/watir/elements/element.rb:534:in `wait_for_writable'
    from /home/jaffejoe/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/watir-6.2.0/lib/watir/elements/element.rb:639:in `element_call'
    from /home/jaffejoe/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/watir-6.2.0/lib/watir/elements/element.rb:303:in `send_keys'
    from watir_test.rb:8:in `<main>' </

这是我的代码:

require 'watir'

browser = Watir::Browser.new

browser.goto('https://tripadvisor.com/CheapFlightsHome')
browser.input(name: 'orig').send_keys('Boston, MA - Logan International Airport (BOS)')
browser.input(name: 'dest').send_keys('Milan, Italy - All Airports (MIL)')
browser.input(name: 'rt_leaveday').send_keys('1')
browser.input(name: 'rt_leavemonth').send_keys('06/2017')
browser.input(name: 'retday').send_keys('30')
browser.input(name: 'leavemonth').send_keys('06/2017')
browser.input(value: 'Search Flights').click
puts browser.url
browser.quit

1 个答案:

答案 0 :(得分:2)

它无法在var user = FormatTextBodyForUserSignIn(userName, password); var httpContent = new StringContent(user, Encoding.UTF8, "application/xml"); var response = client.PostAsync($"api/{TableauAPIVersion}/auth/signin", httpContent).Result; ffmpeg -y -f concat -fflags +genpts -async 1 -safe 0 -i "MergeList.txt" -c copy "Job5_Output.mp4" 上设置值,因为它们是隐藏的输入。但是您可以执行脚本来点击rt_leaveday

rt_leavemonth