Skip to main content

Posts

Showing posts with the label Zoom

How to set the browser's zoom level via JavascriptExecutor in Selenium WebDriver (Java)

Create generic methods like: public void  zoomIn() { zoomValue += z oomIncrement ; zoom(z oomValue ); } public void  zoomOut() { zoomValue -= z oomIncrement ; zoom(z oomValue ); } private static void  zoom( int level ) { JavascriptExecutor js = (JavascriptExecutor) driver ; js .executeScript( "document.body.style.zoom='" + level + "%'" ); } And then call ZoomIn() and ZoomOut() wherever you want. Complete sample code: import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.Test; import io.github.bonigarcia.wdm.WebDriverManager; public class zoomTest { public static WebDriver driver ; private int  z oomValue = 100; private int  z oomIncrement = 20; public void  zoomIn() { zoomValue += z oomIncrement ; zoom(z oomValue ); } pu...

Zoom In And Zoom Out In Selenium using JavascriptExecutor

Zoom In And Zoom Out In Selenium using JavascriptExecutor: public void zoomInOut(String value) { JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.style.zoom='" + value + "'"); } And use the above function as per your need like: public void validateZoom() { WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("https://testersdigest.blogspot.com"); zoomInOut("150%"); zoomInOut("10%"); zoomInOut("40%"); }