I am trying to use selenium ide to duplicate an action. The action is clicking on a link that open a new window. How do you make selenium ide focus on the new window instead of the other one? It has not been working for me.
If you happen to click on a link that launches a separate window, you must first instruct Selenium IDE to select that window first before you could access the elements within it. To do this, you will use the window's title as its locator. Use selectWindow command in switching between windows.
selectWindow (window identifier) - Selenium IDE command The selectWindow | tab=x and selectWindow | title=y commands switch between browser tabs. You can use it with title=(title of tab to be selected, * wildcard is supported) or use tab= with number of the tab (e. g 0,1,2,...).
Open a New Tab get('https://selenium.dev'); // A new tab is opened and switches to it await driver. switchTo(). newWindow('tab'); // Loads Sauce Labs open source website in the newly opened window await driver. get('https://opensource.saucelabs.com/');
Select Window
For this you will need to use the selectWindow | windowName command.
To go back to the main window from the other window then do selectWindow | null
Arguments: * windowID - the JavaScript window ID of the window to select Selects a popup window using a window locator; once a popup windowhas been selected, all commands go to that window. To select the main window again, use null as the target.
Window locators provide different ways of specifying the window object:by title, by internal JavaScript "name," or by JavaScript variable.
* title=My Special Window: Finds the window using the text thatappears in the title bar. Be careful; two windows can share the same title. If that happens, this locator will just pick one. * name=myWindow: Finds the window using its internal JavaScript "name" property. This is the second parameter "windowName" passed to the JavaScript method window.open(url, windowName, windowFeatures, replaceFlag) (which Selenium intercepts). * var=variableName: Some pop-up windows are unnamed (anonymous), but are associated with a JavaScript variable name in the current application window, e.g. "window.foo = window.open(url);". In those cases, you can open the window using "var=foo".
If no window locator prefix is provided, we'll try to guess what youmean like this:
1.) if windowID is null, (or the string "null") then it is assumed theuser is referring to the original window instantiated by the browser).
2.) if the value of the "windowID" parameter is a JavaScript variablename in the current application window, then it is assumed that this variable contains the return value from a call to the JavaScript window.open() method.
3.) Otherwise, selenium looks in a hash it maintains that maps stringnames to window "names".
4.) If that fails, we'll try looping over all of the known windowsto try to find the appropriate "title". Since "title" is not necessarily unique, this may have unexpected behavior.
If you're having trouble figuring out the name of a window that you wantto manipulate, look at the Selenium log messages which identify the names of windows created via window.open (and therefore intercepted by Selenium). You will see messages like the following for each window as it is opened:
debug: window.open call intercepted; window ID (which you canuse with selectWindow()) is "myNewWindow"
In some cases, Selenium will be unable to intercept a call towindow.open (if the call occurs during or before the "onLoad" event, for example). (This is bug SEL-339.) In those cases, you can force Selenium to notice the open window's name by using the Selenium openWindow command, using an empty (blank) url, like this: openWindow("", "myFunnyWindow").
selectWindow(windowID)
selectPopup
If it is a popup then do selectPopUp | windowId and then to go back to the main window do selectWindow | null
selectPopUp(windowID) Arguments:
Simplifies the process of selecting a popup window (and does not offer functionality beyond what selectWindow() already provides).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With