2

I am using Python 2.7 and Selenium 2.39.0. to test a web application. When I run my test as a Windows (7 Ent.) scheduled task with the option "Run whether user is logged on or not", it looks like the screen resolution or window sizing changes; Some buttons become hidden behind the toolbar at the bottom of the browser window and therefore, it can't be clicked by Selenium.

I don't have this problem if I choose the option "Run only when user is logged on"; even if the screen is locked, the buttons are visible and clickable.

According to the Windows task properties, it is using the same user account.

Is there a way, browser setting or a registry key which can help to keep the same resolution and size in both modes?

I know I can scroll down the page, but I am trying to understand and may be prevent this difference of behavior between these two modes.

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • possible duplicate: https://stackoverflow.com/questions/55012755/unable-to-set-window-size-in-selenium-chrome-python – deceze Mar 06 '19 at 15:41
  • Does this answer your question? [How to set window size in Selenium Chrome Python](https://stackoverflow.com/questions/55012755/how-to-set-window-size-in-selenium-chrome-python) – TylerH Jul 29 '22 at 19:45

3 Answers3

2

I've had the same problem. I tried all registry keys I could find, disabled TMM, but to no avail.

Running Selenium with a user logged in seems the only way Windows 7 will give you another resolution than 1024x768. So I ended up setting my Selenium virtual machine like that: have a user log in automatically on startup and launch the Selenium node after that.

Fried Hoeben
  • 3,247
  • 16
  • 14
1

In you selenium test, you can call driver.manage().window().setSize(new Dimension(1920, 1080));

Even if you screen resoltuion is 1024/768 you browser will have the correct window size and you buttons will display just fine.

You can also run your window task with user "SYSTEM". So you don't need to worry about opening the user session.

Mariusz
  • 346
  • 3
  • 6
0

In case anyone comes to this post still looking for the answer as I did.

If you set up the ChromeDriver to run in headless mode using options you can force it to a resolution you want whether the user is logged in or not.

See below which was originally posted by @bunkerdrive in answer to this question:

What is the default window size when running Selenium tests over Azure Pipelines?

Code is C# but I imagine there is a python equivalent to add the options.

var options = new ChromeOptions();
options.AddArguments(new List<string>()
                {
                    "--headless",
                    "--disable-gpu",
                    "--no-first-run",
                    "--no-default-browser-check",
                    "--ignore-certificate-errors",
                    "--no-sandbox",
                    "--window-size=1920,1080",
                    "--start-maximized",
                    "--disable-dev-shm-usage",
                });
driver = new ChromeDriver(options);
Chris L
  • 1
  • 2