Handling “Selenium (WebDriver) Exception: this.getWindow() is null”

I was trying to create a simple script to do few things :
  • Launch Twitter
  • Click on “Sign in”
  • Log in with username "testmail" and password "password"
Relevant Webdriver script is:
public void launchTwitter() throws Exception {
        browser.get("
http://www.twitter.com");
    }
public void clickOn(String string1) throws Exception {
        browser.findElements(By.className("promotional")).get(0).submit();
    }

    public void logInWithUsernameAndPassword(String string1, String string2)
    throws Exception {
        browser.findElement(By.id("username")).sendKeys(string1);
        browser.findElement(By.id("password")).sendKeys(string2);
        browser.findElements(By.className("submit")).get(1).submit();

    }

While trying to play it back on Firefox 4, script failed on below step
browser.findElement(By.id("username")).sendKeys(string1);
and stack trace looked like:
org.openqa.selenium.WebDriverException: this.getWindow() is null
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24'
Driver info: driver.version: RemoteWebDriver
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:409)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:203)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementsByLinkText(RemoteWebDriver.java:221)
    at org.openqa.selenium.By$ByLinkText.findElements(By.java:218)
    at org.openqa.selenium.remote.RemoteWebDriver.findElements(RemoteWebDriver.java:180)
    at Twitter.goBack(Twitter.java:20)
Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: this.getWindow() is null
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_24'
It’s strange! So Google comes to rescue at this point of time. After searching I got that there are lot many others who are facing this issue.
If you don’t want to get re-directed I will post the quick solution, try
browser.switch_to.default_content


As per Simon, this is probably an issue with Firefox and not Selenium. 


Just to note that this works perfectly right with Firefox 3.6.

Comments

  1. thanks, you saved my day ;)

    ReplyDelete
  2. Nishant VermaSeptember 19, 2011

    Selenium Webdriver Version 2.6.0 fixes this issue ! Just tested it !

    ReplyDelete
  3. I have selenium 2.6.11 and it still causing this issue
    2.6.13 - have resolved this issue

    ReplyDelete

Post a Comment

Your comments will be reviewed and then published !

Popular posts from this blog

The 3 qualities that will always help you become better at almost anything…

Embracing the Journey: Finding Joy in the Process

How to install Android Emulator on Windows