Reputation: 5082
As per the mentioned Post, i understood that the ignoreZoomSetting
capability is not yet worked in the Internet Explorer driver.
So, i set the browser level to 100% by manually and i run the test script it is worked as i expected.
Actual Need:
I just want to set the browser zoom level to 100% from my code. I tried to achieve this by using java.awt.Robot class.
Code tried
Robot ignoreZoom = new Robot();
ignoreZoom.keyPress(KeyEvent.VK_CONTROL);
ignoreZoom.keyPress(KeyEvent.VK_0);
ignoreZoom.keyRelease(KeyEvent.VK_CONTROL);
I checked this by setting the browser zoom level to 150% by manually and launched the IE from code.
Code Used to Launch
DesiredCapabilities ieCapabilities = null;
ieCapabilities = DesiredCapabilities.internetExplorer();
driver = new InternetExplorerDriver(ieCapabilities);
The above code opens the IE but at the same time it throws the exception at the third line
of the immediate above code
org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 150%. It should be set to 100% (WARNING: The server did not provide any stacktrace information)
Used Versions:
Selenium server - 2.28.0
OS - Windows 7
IEDriverServer - 2.29.0 (64 bit)
IE - 8.0 (64 bit)
I just want to know is there any possibility to set the zoom level from coding side?
Any help would be appreciated.
Upvotes: 0
Views: 2823
Reputation: 27486
You have a circular dependency here. You want to set the browser zoom level using java.awt.Robot
class, but this can only be done after IE has been launched. However, launching IE with the InternetExplorerDriver
can't be done unless the browser zoom level is set to 100% before the browser is launched. You have two choices.
First, you could set the capability to ignore the zoom level setting of the browser when launching IE. This would get the browser launched, and let you then use the Robot class to set the zoom level at your leisure. I wouldn't recommend this approach, because if setting the zoom level fails for any reason, the IE driver will miscalculate the coordinates of elements, and clicking on elements in the page is likely to fail. If you're dead set on ignoring the zoom level anyway, you'd do something like the following:
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
WebDriver driver = new InternetExplorerDriver(caps);
The second, more correct approach is to simply recognize that because IE doesn't support per-instance profiles (as Firefox and Chrome do), IE is simply going to require some manual configuration on your part before attempting to automate it with WebDriver. Among that manual configuration is to set the browser zoom level to 100%.
The mailing list thread you referred to in your original question does, in fact, state that the ignoreZoomSetting
capability works. The poster in that claims it didn't work for them was attempting to use it improperly.
Upvotes: 2