-1

I need to zoom a particular area in my driver. is there any way to do it? I need not zoom the total browser.

2 Answers2

1

If you want to zoom out a particular WebElement then you can use the below code :

/** It will zoom the given WebElement
     * @param driver
     * @param webElement
     * @param zoomPercentage e.g 200, 100, 50 etc
     */
    private static void zoomElement(WebDriver driver, WebElement webElement,int zoomPercentage) {
        ((JavascriptExecutor) driver).executeScript("arguments[0].style.zoom='" + zoomPercentage + '%' + "' ", webElement);     
    }

here is the actual javascript without customization :

((JavascriptExecutor) driver).executeScript("arguments[0].style.zoom='300%'", webElement);

Hope it helps you.

dangi13
  • 1,275
  • 1
  • 8
  • 11
0

You can try Robot class:

Robot robot = new Robot();

robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_PLUS);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_PLUS);

This will simulate Ctrl + '+' key press, what is equivalent to zoom in. Also you can get more information in documentation.

Andrei Suvorkov
  • 5,559
  • 5
  • 22
  • 48