How can we set the ZOOM Levels [Page Level] in Selenium WebDriver.

How can we set the ZOOM Levels [Page Level] in Selenium WebDriver.

How can we set the ZOOM Levels, like zoom In & Zoom out [Page Level] in Selenium WebDriver.

Zoom In & Zoom Out we generally do on Mobile version but in real world if someone want to zoom in or out on desktop version how to implement the scenario we shall have a small walk through with implementation. With the Help of executeScript() method we can achieve the desired requirement.

What is executeScript() – In general the executeScript() method known as for executing a snippet of JavaScript with the context of selected frame or window. This script area will be executed as the body of identified method. TO store the return value we use the return keyword and give the variable name in the value input.

public class Demo {
	public static void main(String[] args) throws InterruptedException  {		
	   WebDriver driver = new ChromeDriver();
	   JavascriptExecutor jse = (JavascriptExecutor)driver;
	   System.out.println("Zoom In with 200%");
           // Zoom In to 200%
	   System.out.println("Zoom Out with 50%");
           // Zoom Out to 50%
	  System.out.println("Zoom In to Original as 100%");
           // Zoom In to Original as 100%

The below are the screenshots of the different outputs we get while executing the above Selenium Automation code.

Output: Zoom In with 200%

Zoom Out with 50%

Zoom In to Original as 100%

Hope you like this article.

I will come up with another interesting article.

Please provide your valuable feedback in the below comments section.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp