2

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.

NarendraR
  • 6,770
  • 7
  • 35
  • 69

3 Answers3

2
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

Tarun Lalwani
  • 124,930
  • 8
  • 149
  • 214
0

How about something like this one -

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class A {

    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");
        driver.manage().window().maximize();
        Dimension dMax = driver.manage().window().getSize();
        int mHeight = (int) (dMax.height *.9);
        int mWidth = (int)(dMax.width *.9);
        Dimension d = new Dimension(mWidth, mHeight);
        driver.manage().window().setSize(d);
        System.out.println( driver.manage().window().getSize());

    }

}
eduPeeth
  • 1,620
  • 11
  • 19
0

There is not the capability level option is available in Firefox. But screen size can be increased or decrease by webdriver:

driver.manage().window().setSize(value);
Ankit Gupta
  • 627
  • 4
  • 11