Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium Chrome window running in second monitor screen stealing focus

I use WebDriver with Chrome Driver 2.35 with Selenium.

I have a dual monitor setup in which I run my test cases. I do run my cases headlessly most of the times but sometimes, when I want to debug, I run it with the browser.

The window opens, I drag it to my second monitor and continue working with other stuff in my primary monitor. But whenever there is an action in the secondary Chrome Selenium screen, the focus shifts to that window and I lose control.

This is really annoying, has anyone else faced this issue? Any solutions?

like image 656
whydoieven Avatar asked Feb 28 '18 08:02

whydoieven


People also ask

Does Selenium run in background?

Selenium Webdriver can run in the background, i.e. without opening a browser window, by running it in Headless mode. To do this you need to add the required capability to the set-up code for the driver. In Python with Chromedriver you need to add the following line of code when writing the chrome_options: ?

How to handle new browser window in selenium WebDriver?

Get the handles of all the windows that are currently open using the command: Set<String> allWindowHandles = driver. getWindowHandles(); which returns the set of handles. Use the SwitchTo command to switch to the desired window and also pass the URL of the web page.

What is Cookies in selenium?

Krishna Rungta August 27, 2022. A HTTP cookie is comprised of information about the user and their preferences. It stores information using a key-value pair. It is a small piece of data sent from Web Application and stored in Web Browser, while the user is browsing that website.


1 Answers

Selenium chromedriver does steal the focus only once at startup. Afterwards you can run the browser in the background without any problems (we're doing it that way, using chromedriver 2.30, so I'm sure it works)

Therefore you probably have some code in your web tests which performs the focus stealing:

1) Changing the active window or opening a new window / new tab causes focus stealing.

2) You explicitly call Focus() on an element.

Are you sure your code is free of such calls?

like image 200
D.R. Avatar answered Sep 18 '22 12:09

D.R.