Watir Webdriver attach window
While porting a watir based automation framework to watir-webdriver, I came across an issue that most have come across, that being : "In Watir and Selenium Webdrivers, there is no longer an attach method to attach to existing browsers. "
But an in-depth analysis of the rspec for watir-webdriver brought a simple method to the lime light.
browser.windows #=> [#, #]
browser.windows.first.current? #=> true
browser.windows.last.use
browser.windows.first.close
browser.window(:title => "foo").use
browser.window(:url => /bar/).use { ...code... }
browser.windows.first.current? #=> true
browser.windows.last.use
browser.windows.first.close
browser.window(:title => "foo").use
browser.window(:url => /bar/).use { ...code... }
As the above code makes it clear, it's easy to switch between windows, even though the 'attach' method is missing in the webdriver.
Alternatively one can also use
browser.driver.switch_to.window(browser.driver.window_handles[0])
But that would get complicated with too many popups to handle. Interestingly there is one issue still lurking around in the Selenium world!
Recent blog posts
- watir-webdriver web inspector
- gem list to gemfile
- Packing ruby2.0 on debian.
- Made it into The Guinness Book!
- to_h in ruby 2.0
- Filter elements by pattern jQuery.
- Better HTML password fields for mobile ?
- Grayscale image when user offline
- nth-child CSS pseudo-class Christmas colors
- EventEmitter in nodejs