我认为导致问题的原因是 http 请求需要一些时间才能加载,请尝试放置类似
sleep 1 until b.a(:class, "jewelButton").exists?
就在您的第 5 行下方。
还有为什么不:b.button(:text, "Log In").click
而不是b.form(:id,'login_form').submit
?
在 irb 中,无论哪种方式都可以正常工作:
irb(main):001:0>require "watir-webdriver"
=> true
irb(main):002:0>b = Watir::Browser.new :chrome
Started ChromeDriver
port=55320
version=22.0.1203.0b
log=C:\Users\your_username\chromedriver.log
=> #<Watir::Browser:0x..fc4b0180c url="chrome://newtab/" title="New Tab">
irb(main):015:0> b.goto "facebook.com"
=> "http://www.facebook.com/"
irb(main):003:0>b.text_field(:id,'email').set(usr)
=> {}
irb(main):004:0>b.text_field(:id,'pass').set(pwd)
=> {}
irb(main):005:0>puts 'form submit'
form submit
=> nil
irb(main):006:0>b.button(:text,"Log In").click
=> nil
irb(main):007:0>puts "blah blah"
blah blah
=> nil
irb(main):008:0>b.a(:class, "jewelButton").click
=> []
irb(main):010:0>b.a(:class, "jewelButton").click
=> []