Posted in Automation Testing

Selenium: How to resolve zoom level error in IE

Many a times when we run automated test using selnium in IE browser, we get below error:
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 125%. It should be set to 100%

Reason:
When the default zoom is set not at 100% and due to which, the IEDriverServer throws exception as it is expecting the value as 100% so that it can click at the middle.

Solution:

1- Using Internet options (Selenium)

2- Using IE Browser setting
https://www.softwaretestingmaterial.com/failed-to-launch-ie-driver-using-selenium/

3- Using javascript executor
driver.executeScript(“document.body.style.zoom=’100%'”);

4- Using key actions
driver.findElement(By.tagName(“html”)).sendKeys(Keys.chord(Keys.CONTROL, “0”));

5- Using Desired capabilities ( Deprecated )

DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
aDriver = new InternetExplorerDriver(caps);

Conclusion:
So which one should we use?
In my opinion,
– we must choose one that works for not only IE but also other browsers too (Even though not required).
– We should use a solution which is compatible with remote machines without doing any extra level of setting ( IE browser setting is ruled out , as it needs extra setup )
– we do not want our code to be changed when we change our browser type.
And also we do not want to use deprecated solution as it might create issue in future due to incompatibilities after updated dependencies. (#5 is ruled out )

So we are left with #3 (javascript executor ) and #4 (Key action) which works well for all browsers and no extra setup needed.

Let me know your thoughts , if you have any better solution, write me in the comments.

Leave a comment