EdgeWebDriver icon indicating copy to clipboard operation
EdgeWebDriver copied to clipboard

Need to zoom in to edge browser in automation using selenium C#

Open SaranKumar1997 opened this issue 2 years ago • 4 comments

using options.AddArgument("--force-device-scale-factor=1.25"); makes no difference

using js.ExecuteScript("document.body.style.zoom = '110%'"); is working, but it is not reflecting in edge option and after that unable to do actions like click getting ElementNotInteractableException

SaranKumar1997 avatar Jun 29 '23 03:06 SaranKumar1997

Hi @SaranKumar1997. The --force-device-scale-factor command line arg changes the device scale factor (a.k.a. the device pixel ratio) as seen by the browser. You can verify this is working by looking at window.devicePixelRatio in script. It may cause the window and graphics to appear larger by default, but it won't actually change the page's zoom. Can you tell me more about what you are trying to do?

bwalderman avatar Jul 05 '23 16:07 bwalderman

Hi @bwalderman. There is a requirement that I have to zoom into the edge browser and automate it. so I need a line of code that will result in the change in zoom in of browser and the zoom level in browser needs to be changed like below. image

SaranKumar1997 avatar Jul 06 '23 04:07 SaranKumar1997

Have you considered java.awt.Robot? The below code snippet zooms in 10%, so assuming your default zoom level is 100% this should bring it to 110%:

		public void testZoom () throws AWTException
	{
		// Instantiate the WebDriver
		WebDriver driver = new EdgeDriver();
		// Navigate to the specified URL
		driver.get("https://google.com");
		// Initialise the Robot object
		Robot robot = new Robot();
		// Simulate increased page zoom by sending "Ctrl" and "+" keypresses
			robot.keyPress(KeyEvent.VK_CONTROL);
			robot.keyPress(KeyEvent.VK_ADD);
			robot.keyRelease(KeyEvent.VK_ADD);
	}

Note: There are undoubtedly more elegant ways to accomplish this, but it worked for me without fail before I devised a way to set a restored browser window using factors of a maximised window by dividing its dimensions.

Edit: I'm sorry, I did not notice the C# tag in your post. I believe there is a way to send that key combination using C#, though.

jbakeri4 avatar Jul 14 '23 23:07 jbakeri4

Hi @SaranKumar1997

using js.ExecuteScript("document.body.style.zoom = '110%'"); is working, but it is not reflecting in edge option and after that unable to do actions like click getting ElementNotInteractableException

ElementNotInteractableException indicates the elements may not be visible in the window after zooming. You may need to make the window bigger or scroll the elements into view first.

bwalderman avatar Dec 08 '23 08:12 bwalderman