Any thoughts on handling windows interaction between multiple windows using selenium

Hi All,

Please find below use case:

Use Case: 1. Interaction happens between two active windows. How can be handled in automation using selenium.

1 Like

Wow, coincidence Vijitha.

I wish I could give you examples as I go, but this is an area I’ve also just encountered. I’m using a “remoted” Python solution, which means I’ve made my life impossible because selenium implements multiple tabs using a method that either returns a new context or just actively switches the tab focus. My smart remoting is like spaghetti, but that’s a side issue for me to fix.

I suspect it only allows interaction with tabs that are visible at the time. Need to confirm whether undocking of tabs and then tiling them will let you do what you want, but need to re-architect my spaghetti first.

driver.window_handles # property returns all open tabs
driver.execute_script(“;”) # open a new tab
driver.switch_to.window(driver.window_handles[1]) # select a tab using 2nd handle in the list
#` the list of handles is apparently a bit randomly ordered, so relying on it being sequential might be a mistake when switching tabs

The above python fragments hopefully give some clues. I’ve not worked out how to undock tabs yet. I assume you mean tabs, not windows. Because multiple windows implies multiple copies of the selenium driver running? I hope I understood right?

1 Like

Thank Conrad! for the quick reply.
I was looking for multiple windows invoke. with selenium4 able to achieve as below
WebDriver driver = new ChromeDriver();
WebDriver newWindow = driver.switchTo().newWindow(WindowType.WINDOW);

Vijitha Yes.
That sounds like the route that the webdriver folks wanted us to go down. Thanks for sharing those steps.
Does that actually spin up a new webdriver process/server as well? I’m actually at a point where I want to handle users opening a page in a new tab, which is why I am approaching the window_handles property, to be able to find and control the new tab after the navigation gets done by the browser engine.

Sorry my names are all Python names, not Java. I am not yet one of the cool kids. :slight_smile:

Hi Conrad,
Yes its spin a new webdriver. Even tabs can be handled as below:
for tabs, as you mentioned above, it works that way too :slightly_smiling_face:

While I have you Vijitha - I’m looking at remote control differently lately. I have to test on IOS, linux and Windows too and I’m using my remoting framework (Python) in my own test framework to allow me to run selenium “locally” and no “server”. My Test Framework runs tests remotely, so the selenium always is “local”. I want to step this up a bit though. What struck me, is there is no proper explanation of how selenium remoting servers work and what you need to do to set up. Nobody has a tutorial showing how to control a remote machine with 3 browsers installed on it. I still need to put a webdriver for each browser onto that remote machine I assume? Or am I dreaming?

At the moment I have this

  1. my test FW remotely copies the webdriver binary to the remote. It’s a farm of dozens of machines that run loads of other kinds of tests, the machines are largely clean, no JRE installed, only Python.
  2. my FW then calls into selenium lib on the remote, and chooses a Driver with the binary path from step 1, and then off I go.

I effectively use selenium remotely, but my test FW does all the remoting, I have a wrapper library that remotes all of my calls, and it’s painful. But advantage is selenium is only talking local right now. I want to rip out my remoting layer and use the “selenium.remote” class and get my framework to just stop and start the server for me. But the server is a Jar, so I now must auto-install JRE on every node, and that’s a pain to do on IOS, so I’m a bit puzzled. I feel like I’m creating work for myself. I also assume that when I use Server, I would still have to copy the webdriver binaries to each remote, but that I just give selenium.remote wrapper the path to those binaries for each browser like I had to do before?

Sorry the time hijack, but hope you can spend some time to fill me in.


Blockquote By integrating selenium with docker, tests can be executed in different OS in local or remote.
I have configured for our project. It seemlessly works in any OS or browser.
With this tests can be executed in parallel.
As we are using docker, it executes on light weight, nodes will spawn randomly and once execution is done it turns off the node. which provides better usability.

Providing link below for the details on how to configure selenium with docker

Hope this helps you!

1 Like

I’m keen to use headless mode, and docker containers, but also wary of loosing the ability to do exploratory testing on “real” machines where users have unusual browser configurations or plugins loaded that may hamper their experience unwittingly. A bigger fear is Safari and Mac get zero coverage in Docker, and over half of our sales, devs and other staff use mac, but with Chrome which does remove a lot of risk I guess.

(Even though FF and Chrome are ~90% of the browser connections, ignoring MacOS, Edge and Safari still feels dangerous. Mainly because those are the out-of-box experience a first-time may see.)

Good to see people getting this working well, I love Docker, but it’s often harder to work out how to balance the testers time between building and maintaining the smart infrastructure and doing real free-form exploratory tests. Right now I’m early in a project, so the value of regression tests is pretty low. Guess I need to build a roadmap and build it in stages. Thank you for the inspiration here Vijitha.