I have an app where a user could be looking at 2 possible browser windows / tabs.
If the user is in Window 2 and an event occurs in Window 1, I change the text of the title bar using JQuery Title Alert (https://github.com/heyman/jquery-titlealert) as a way of notifying them that something is going on in Window 1. The title text change will flash until Window 1 is focused.
All this works fine. However, I want to integration test this using capybara and selenium and I’ve hit an interesting problem. While I can switch between windows easily using something like:
page.driver.browser.switch_to.window(page.driver.browser.window_handles.last)
I want to be able to get the Text of the unfocused window to test that it’s text has changed. Does anyone know how to:
- Get the titles of all the windows?
- inspect properties of a window without switching to it / focusing on it?
- any other way I could approach this problem?
Thanks in advance for the help!
You can use the
WebDriverBackedSeleniumwhich has aGetAllWindowTitles(). It should work in Ruby with the latest version 2.19. The following example in C# works.The output is as expected: