Im trying to implement the following methods from selenium-webdriver (ruby)
- get_all_window_ids
- get_all_window_titles
- get_all_window_names
- I ran Selenium IDE and exported my script to Ruby Test::Unit. Saved it as .rb
- Opened my script for editing using Aptana Studio 3
- Initial code snippet as follows:
require "rubygems"
require "selenium-webdriver"
require "test/unit"
class SwitchToPopup3 < Test::Unit::TestCase
def setup
@driver = Selenium::WebDriver.for :firefox
@base_url = (URL of my test website)
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
def teardown
@driver.quit
assert_equal [], @verification_errors
end
def test_switch_to_popup3
.
.
puts @driver.get_all_window_ids()
puts @driver.get_all_window_titles()
puts @driver.get_all_window_names()
.
.
end
The error I keep getting is
NoMethodError: undefined method `get_all_window_ids' for # <Selenium::WebDriver::Driver:0x101e4b040 browser=:chrome>
/Users/rsucgang/Documents/Aptana Studio 3 Workspace/Testing/SwitchToPopup2.rb:37:in `test_switch_to_popup3'
I've studied the documentation for the ruby bindings for selenium-webdriver
Ultimately my goal here is to run my automation script:
- Click on a link that opens a new window with target=_blank and no windowID available (does not implement JS)
- Identify the names of all opened windows in the browser
- switch to a new pop-up window using the switchToWindow(name) method
- continue running my script on that pop-up window
I've googled and researched this on the internet and I have not gotten any much information.
Thanks and please let me know if you need more information.
- OSL Mac OSX 10.7.3
- Ruby: ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
- Browser: Firefox 9.0.1 (Mac)
- Chrome: Chrome 17.0.963.79 (Mac)
- Selenium-Server: Ruby gem 2.20.0
Best Solution
Justin, you have a good approach. But there is a gotcha in assuming that the window handles will return in the correct order. This isn't always the case across all browsers. I outline a slightly different approach in my free weekly Selenium tip newsletter (elemental-selenium.com).
It goes like this:
You can see the full tip here.