ChromeOptions to set browser zoom to 80%

左心房为你撑大大i 提交于 2019-12-11 06:05:55

问题


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;
}

回答1:


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



来源:https://stackoverflow.com/questions/47925135/chromeoptions-to-set-browser-zoom-to-80

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!