How to set zoom level for MS-Edge in IE MODE browser using selenium 3.141.59 on windows 11?

753 Views Asked by At

I am automating a web application in ME-Edge in IE Mode on Windows 11. I have to set zoom level to 80% for same requirement for all end to end test cases. I tried with multiple given code // To zoom out 3 times

for(int i=0; i<3; i++){
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL,Keys.SUBTRACT));
}

Also tried with JavascriptExecutor, but its working for launching page, once logged in and it goes to next page where browser zoom will be 100% again and execution stops.

 JavascriptExecutor jse = (JavascriptExecutor)driver;
       Thread.sleep(3000);
       System.out.println("Zoom with 80%");
              jse.executeScript("document.body.style.zoom='80%'");

Also, tried with press CTRL+SUBTRACT but script stops further execution.

System.setProperty("webdriver.ie.driver",
                    FileReaderManager.getInstance().getConfigReader().getDriverPath()
                            + "\\IEDriverServer32bit.exe");
            InternetExplorerOptions edgeIe11Options = new InternetExplorerOptions();
            Map<String, Object> ops = (Map<String, Object>) edgeIe11Options.getCapability("se:ieOptions");
            ops.put("ie.edgechromium", true);
            ops.put("ie.edgepath", "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");                edgeIe11Options.introduceFlakinessByIgnoringSecurityDomains();
            edgeIe11Options.ignoreZoomSettings();
            edgeIe11Options.enablePersistentHovering();
            edgeIe11Options.getBrowserName();
            edgeIe11Options.takeFullPageScreenshot();
            // edgeIe11Options.disableNativeEvents();
            edgeIe11Options.requireWindowFocus();
            edgeIe11Options.destructivelyEnsureCleanSession();
            edgeIe11Options.setCapability("ignoreProtectedModeSettings", true);
            edgeIe11Options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.IGNORE);
            
            driver = new InternetExplorerDriver(edgeIe11Options);
1

There are 1 best solutions below

0
Kendrick Li On

You have almost every possible means of setting the zoom level, but it usually will not cause any issue except when you perform some mouse action. Notes from Selenium docs:

The browser zoom level must be set to 100% so that the native mouse events can be set to the correct coordinates.

So I would suggest restoring the browser zoom level to 100% when you need to perform mouse action, and zoom in/out when you actually need it, though it may sound rather complicated.