2

I am using Watir with Chromedriver to automate form submission on some website. I have to login and submit multiple forms. The problem is, when I click the submit button the page the page automatically closes, so when I goto('next_url') I get this error:

/Users/jackz/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.27.2/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok': 'auto_id' does not refer to an open tab (Selenium::WebDriver::Error::UnknownError)

The Watir instance is still there, but the window is closed. I could create a new instance every time, but then I would have to login again every time and this would take longer.

So how can I either:

Open a new window in the same Watir instance

or

Suppress the window from closing after I submit

require 'watir-webdriver'
@b = Watir::Browser.new :chrome
@b.goto(URL)
@b.buttons.first.click

#this is when the window closes
@b.goto(NEW_URL)
#then I get an error

Thanks

4
  • Does the window close automatically when you do the same thing manually? Commented Jan 3, 2013 at 21:06
  • Yes, successfully submitting anything on the page manually or through Watir closes it.
    – jz999
    Commented Jan 3, 2013 at 21:29
  • 1
    In that case you should as the developers what you should so the window does not close. Commented Jan 4, 2013 at 8:37
  • 1
    Ah yea asking the developers is probably not an option, I am using a web application developed by a giant bank...I figured out a workaround to the problem though. Thanks.
    – jz999
    Commented Jan 4, 2013 at 17:24

3 Answers 3

2

I figured out an answer to my own question. I can open a new window in Watir using javascript:

b = Watir::Browser.new
b.execute_script("window.open()")
b.windows.last.use

This opens a window where I can fill out the form, then when the window automatically closes I still have the original window to work with. Probably not the best solution, but it works for now.

1

Add this to your existing code if your using chrome. else, modify accordingly as per your browser.

This will keep the window open, and the current watir session active.

caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {'detach' => false})
browser = Watir::Browser.new :chrome
1

What Mrityunjeyan suggested above was in a right direction, but you need to change a few things to make it work.

caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {'detach' => true })
b = Watir::Browser.new('chrome', desired_capabilities: caps)

Check the documentation here. https://sites.google.com/a/chromium.org/chromedriver/capabilities

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.