1

Okay, this is a weird one.

I'm running Java 8b144, Selenium 3.9.0

I'm setting the resolution size of the driver:

driver.manage().window().setSize(new Dimension(1920, 1080));

When I execute the test and the browser opens, the webpage extends beyond just one monitor (screen resolution is set to 1920x1080) and text/image sizes are all significantly larger making it so I have to scroll right to see the rest of the web page I'm testing. When I open a browser manually the the text/image sizes are all normal.

When I open a browser and go to Yelp manually I get: enter image description here

When Selenium launches I get (notice the much larger text and image size): enter image description here

If I kill the test and then check the "text size" from the browser menu it's still set to 100% - the same as when I do this manually.

I've also tried:

chromeOptions.addArguments("--window-size=1920,1080");

and

caps.setCapability("resolution", "1920x1080");

but those don't seem to have any effect.

I'd like to have Selenium launch the browsers and run the tests at the same resolution as when I manually do this.

Does anyone have any ideas?

Anton
  • 761
  • 17
  • 40

3 Answers3

8

Apparently starting in Chrome 54 the default UI size was increased. https://productforums.google.com/forum/#!topic/chrome/DhTFXA-vcgI

The only way that I have been able to successfully get the size of the text and images back to normal is to send in these arguments when launching the browser.

chromeOptions.addArguments("force-device-scale-factor=0.75");
chromeOptions.addArguments("high-dpi-support=0.75");

You can adjust the values to what you want. The new default UI size is 1.25. So just setting the value "=1" will give you the original UI size.

This feels more like a work around than a solution. I hope that chromeDriver will have an option to make the scale more easily accessible in the future.

Anton
  • 761
  • 17
  • 40
  • It doesn't explain why you are getting a different resolution between automated vs manual. Could it be that you launched the browser in a different screen or station? – Florent B. Apr 18 '18 at 14:23
  • 1
    @FlorentB. I spent two days trying to uncover the underlying cause with no success. I had to just implement this work around and move on. The browser was launched on the same machine and navigates to the same page. This is why I was so confused. This isn't just occurring for me it's occurring for everyone on my team. I checked with a few friends at another company and they noticed the same behavior. Thus far none of us have been able to figure it out. – Anton Apr 18 '18 at 17:24
  • Interesting though I haven't been able to reproduce the issue. The difference when launched manually could be due to the updates which led to a profile different from a fresh one. I would try to delete the profile from the user (see `chrome://version/`) to see if the difference remains. – Florent B. Apr 18 '18 at 17:55
0

Hi is there a specific reason you are defining the custom size?

Try

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

OR starting the browser in maximized state

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
WebDriver driver = new ChromeDriver(options);

OR try this solution by adding another option to ChromeOptions

  • Yes, I've tried all of these options. The text/image size is significantly larger when chrome starts via selenium for some reason. I have to manually decrease the zoom to like 67% in order for everything to display normally. This only occurs when Selenium starts the browser. – Anton Apr 17 '18 at 17:29
  • check this out [link](https://stackoverflow.com/a/15025302/8880880) looks like you might have to use the keyboard to decrease zoom size. Let me know if that works for you :) – Oskar Dauksts Apr 17 '18 at 17:45
  • https://productforums.google.com/forum/#!topic/chrome/DhTFXA-vcgI Please see my posted solution above. – Anton Apr 17 '18 at 19:25
0

You can add one line of code

JavascriptExecutor js = (JavascriptExecutor) driver;  
js.executeScript("document.body.style.transform='scale(0.9)';");

You can vary the value 0.9 to any value as per your requirement. Hope it helps

  • I tried this one but it had no effect on the scale. Maybe it's the site I'm testing against? – Anton Apr 18 '18 at 17:27