Thursday, 9 February 2017

SELENIUM: How To Resolve Set IE browser Zoom Level To 100% Error On RunTime


How To Resolve Set IE browser Zoom Level To 100% Error On RunTime:

If your IE browser zoom level Is not set to 100% then you will get an error like "Browser zoom level was set to XYZ%. It should be set to 100% ".
 To resolve this error by setting IE browser's zoom level to 100% manually before running software test automation script.

Now If you need to run your software test script In different computers then everywhere you need to set browser's zoom level every time manually before running your software web application's test script.

Otherwise your software automation test script will fail.

Here we will use same class DesiredCapabilities of WebDriver Interface which we have used In previous post to resolve error. Here we will set browser's capability to Ignore zoom setting and disable the native events. Then we will set browser zoom level to 100%.



Step1:
// Set desired capabilities to Ignore IEDriver zoom level settings and disable native events.

DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("EnableNativeEvents", false);
caps.setCapability("ignoreZoomSetting", true);

Step2:
// Initialize InternetExplorerDriver Instance using new capability.
WebDriver driver = new InternetExplorerDriver(caps);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

Step3:
// Press CTRL + 0 keys of keyboard to set IEDriver Instance zoom level to 100%.
driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));



Example:

package com.rameshsoft.rameshselenium;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class ZoomLevelIE {
          @Test
           public void setup() throws Exception {
          System.setProperty("webdriver.ie.driver", "C:\\Users\\ramesh\\Desktop\\java\\desk\\IEDriverServer_x64_2.53.1\\IEDriverServer.exe"); 
          DesiredCapabilities capability=new DesiredCapabilities();
          capability.setCapability("EnableNativeEvents", false);
          capability.setCapability("ignoreZoomSetting", true);
            WebDriver driver = new InternetExplorerDriver(capability);           
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);            driver.findElement(By.tagName("html")).sendKeys(Keys.chord(Keys.CONTROL, "0"));
            driver.get("http://google.com/");
           }
           


}

No comments:

Post a Comment