I need to zoom a particular area in my driver. is there any way to do it? I need not zoom the total browser.
Asked
Active
Viewed 470 times
-1
-
How do you do that manually? Relevant HTML, code trials, error (if any)? – undetected Selenium Jul 02 '18 at 12:26
-
I don't think you can perform that, without a plugin. Probably if you say us your use case, we can find a solution. – KunLun Jul 02 '18 at 12:27
-
If you want to zoom page content, refer - https://stackoverflow.com/questions/15024756/selenium-webdriver-zoom-in-out-page-content – Shivam Mishra Jul 02 '18 at 12:51
2 Answers
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
-
-
Yes, you are right. Didn't noticed `not` in `I need not zoom the total browser` – Andrei Suvorkov Jul 02 '18 at 12:56