Arthur
Arthur

Reputation: 3797

IE7 - NoSuchElementException with Selenium

I'm trying to use Selenium on IE7 with InternetExplorerDriver on Windows XP. This code works fine with Firefox, IE9 and even IE9 in compatibility mode (on W7).

HTML:

<HTML xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE></TITLE></HEAD>
<BODY>
<div id="login">chicken</div>
</BODY>

Building driver:

private static WebDriver getIE7WebDriver() {
    WebDriver driver = null;
    DesiredCapabilities capabilities;
    capabilities= DesiredCapabilities.internetExplorer();
    capabilities.setCapability(InternetExplorerDriver.FORCE_CREATE_PROCESS, false);
    capabilities.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS,true);
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "internet explorer");
    capabilities.setCapability(CapabilityType.PLATFORM, "WINDOWS");
    capabilities.setCapability(CapabilityType.VERSION, "7");

    System.setProperty("webdriver.ie.driver",(new File("C:\\selenium\\IEDriverServer.exe")).getAbsolutePath());
    try {
        driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return driver;
}

And trying to get my #index element:

log.info(driver.getPageSource());

try {
    String value = driver.findElement(By.cssSelector("#login")).toString();
    log.info(value);
}
catch ( Exception e ) {
    log.error(e.toString());
}

Page source is fetch properly, but anytime I try to access an element, I get a org.openqa.selenium.NoSuchElementException. I also tried by id and XPath.

Any idea of what's going wrong ?

PS: In Windows XP, there is no security mode for IE.

EDIT: driver.getPageSource() returns:

<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"><HEAD><TITLE></TITLE></HEAD>
<BODY>
<DIV id=login>chicken</DIV></BODY></HTML>

Upvotes: 7

Views: 399

Answers (2)

user861594
user861594

Reputation: 5908

For IE 7 selenium server version 2.20 or below should given a try. Recently we face similar issue where few commands were working in IE 10 but not working in IE 8. When we downgrade upto selenium 2.20 (tried one by one) and it worked fine for IE 8 with 2.20. If you are using hub then make sure node running selenium server has older vesion (<2.20) of selenium running.

Upvotes: 1

ddavison
ddavison

Reputation: 29032

Ok - per the comments, you specified that you weren't running against the hub, yet, in your code - you point to a hub. I think it has something to do with this.

Change this block of code:

try {
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

to:

driver = new IEDriver(capabilities);

RemoteWebDriver(new URL("http://localhost:4444/wd/hub") this piece here is pointing your test to some remote driver, which means "a selenium node that is connected to a hub." You've already confirmed that this you are not using a hub, so this answer should solve your issue.

A breakdown:

RemoteWebDriver() = Selenium Node that is connected to a hub
ChromeDriver|IEDriver|FirefoxDriver = Local browser session

Upvotes: 1

Related Questions