To zoom in webpage on browser I searched solution and used following ways but I am receiving either an error or no zoom effect. Can someone please help me to identify where is the mistake or what's wrong with the code. Browser I am using is Chrome.
First method:
element = driver.findElement(By.tagName("html"));
element.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));
Error received on this: Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element
To solve above error I tried:
element = driver.findElement(By.tagname("html"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.sendKeys(Keys.CONTROL, Keys.ADD);
actions.build().perform();
Error received: unknown error: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
Also I tried to replace element html
with body
but zoom not worked
Third way:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.body.style.zoom='80%'");