Simulating Browser Zoom Controls with Selenium

Selenium Zoom Example

Though such scenarios are not common in automation activities, you may encounter need to simulate browser zoom operation. These scenarios are common if you need to carry out accessibility testing. In this tutorial, we have implemented Selenium zoom example with Java’s Action class.

Zoom In and Zoom Out operations are carried out by ‘CTRL +’ and ‘CTRL – ‘ key press respectively. We will simulate these commands in Selenium WebDriver using Action class. Commands for those are Keys.chord(Keys.CONTROL, Keys.ADD) and Keys.chord(Keys.CONTROL, Keys.SUBTRACT). Similarly for zooming back in to the default level, Keys.chord(Keys.CONTROL, “0”) command is used.

To apply zoom on web page, we need to reference it with its HTML tag by using driver.findElement(By.tagName(“html”)) code. Now, let’s see the above commands in action with below code.

The above code example will zoom web page in by 5 levels, zoom out by 1 level and will return to the default zoom level.

As you can see from the above steps, Selenium zoom implementation is easy using Selenium WebDriver. Try it out at your end and let us know how it goes.

Reference

Comments
  1. Mukesh
  2. sanjay
  3. Aviraj
  4. asdf

Leave a Reply

Your email address will not be published.