Monday, August 26, 2013

Selenium WebDriver

Two lessons learned

  • IE driver need to start with "ignoreZoomSettings" true
  • JavascriptExecutor return for JS object

IE driver need to start with "ignoreZoomSettings" true

Got this error when using WebDriver for IE: "
org.openqa.selenium.remote.SessionNotFoundException". Turns out I was using IE to visit the same site I'm testing, and I adjusted zooming to 120% there. Fix for this problem is easy, simply change IE web driver creation to this:


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

JavascriptExecutor return for JS object

What can be returned from JavaScriptExecutor.executeScript? According to the documentation, these are the types that it handles: Boolean, Long, String, List, or WebElement or null. I did a little experiment, and pleasantly surprise by the fact that array of JSON can be handled too. The return will be ArrayList of Maps. Calling obj.toString (Java side) will actually give me expected JSON string too.
Figure: Return Object as Shown in Eclipse Variables View

No comments: