MicrosoftEdge / EdgeWebDriver

Feedback and discussions about WebDriver for Microsoft Edge
MIT License
55 stars 7 forks source link

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

Open SaranKumar1997 opened 1 year ago

SaranKumar1997 commented 1 year ago

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

bwalderman commented 1 year ago

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?

SaranKumar1997 commented 1 year ago

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

jbakeri4 commented 1 year ago

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.

bwalderman commented 9 months ago

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.