3

I would like to set the default zoom value to 80% when opening the browser for a selenium framework. Something along the lines of below. Is this possible with ChromeOptions.

private static ChromeOptions GetChromeOptions()
{
    ChromeOptions options = new ChromeOptions();
    options.AddArgument("--start-maximized");
    options.AddArgument("Zoom 80%");
    return options;
}
Ross
  • 1,875
  • 17
  • 50
  • The product I am creating the framework is only slightly too big for the browser resolution we use. I thought it would be easier to have the browser set to 80% zoom so that I can take a screenshot of the whole page easily rather than figuring out how to stitch multiple screenshots together. – Ross Dec 21 '17 at 12:43
  • So your underlying issue is you want to take screenshots? – mjwills Dec 21 '17 at 12:44
  • https://stackoverflow.com/questions/15024756/selenium-webdriver-zoom-in-out-page-content -- this question can be helpful for you. – Ratmir Asanov Dec 21 '17 at 12:45

1 Answers1

2

To to set the zoom level to 80% you can use Javascriptexecutor with either of the following options :

((IJavaScriptExecutor)driver).executeScript("document.body.style.transform='scale(0.8)';");

or

((IJavaScriptExecutor)driver).executeScript("document.body.style.zoom='80%';");

Note : Deviating from the standard default zoom value of 100% may impact the functioning of the Web Browsers

DebanjanB
  • 118,661
  • 30
  • 168
  • 217