Search code examples
javaseleniumfirefoxselenium-webdriverdesiredcapabilities

Is there any capabilities to set Firefox browser zoom level to some specific percent throughout script execution?


I'm using Firefox browser and i want to set the zoom level 90% while it executing the script.

I have tried to set using JavascriptExecutor like -

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

Its working for specific command lets say in my Listeners file i have place this if its a get command. it resize the browser after get URL and then it restored back to default once another command getting executed.

I'm looking for the solution like DesiredCapabilities of things so there i can add the zoom level for the browser.


Solution

  • FirefoxProfile profile= new FirefoxProfile();
    profile.setPreference( "layout.css.devPixelsPerPx", "0.9" );
    WebDriver driver = new FirefoxDriver(profile);
    

    The above will set the firefox profile preference and simulate a zoom level of 90% for 110% set it to 1.1