简体   繁体   中英

watir after form submit

I am new to WATIR+Ruby. I am trying to continue to test after logging into a form like this

browser.link(:name, 'login-facebook id=').click
browser.text_field(:id,'email').set(usr)
browser.text_field(:id,'pass').set(pwd)
puts 'form submit'
browser.form(:id,'login_form').submit
puts 'hello world'

upto login works. I see form submit and form is submitted. But can't go further. Don't see 'hello world'

I think what's causing the problem here is the http request which is taking some time to load, try putting something like

sleep 1 until b.a(:class, "jewelButton").exists? 

right below your 5th line.

Also why not: b.button(:text, "Log In").click instead of b.form(:id,'login_form').submit ?

In irb it works fine either way:

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
=> []

Assuming you use new lines for all commands (unlike the block of code you pasted), my first thought is that the console will not display text output until the end of the test unless you have buffer sync turned on. Is it possible you're not waiting for the script to finish?

Add this line to the top of your script and see if that resolves the issue.

$stdout.sync = true
browser.link(:name, 'login-facebook id=').click
browser.text_field(:id,'email').set(usr)
browser.text_field(:id,'pass').set(pwd)
puts 'form submit'
browser.form(:id,'login_form').submit
puts 'hello world'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM