Suvasish Sarker
Suvasish Sarker

Reputation: 435

IE11 is failing to find element by using xpath while it works fine in Chrome in Selenium

HTML

<tr>
    <td class="label" width="30%" valign="bottom">SOID:
        </td>
    <td class="desc" valign="top">123456789</td>
</tr>

Iam intersted in the value "123456789"

Xpath

".//td[contains(@class,'label') and contains(.,'SOID:')]/following-sibling::td"

Code

public string MyMethod()
{
    string soidXpath = ".//td[contains(@class,'label') and contains(.,'SOID:')]/following-sibling::td";
    IWebElement soidElem = driver.FindElement(By.XPath(soidXpath));
    return soidElem.Text;
}

With this xpath my test passes in chrome but fails in IE11 with the below...

Error

Test 'H.Auto.RegressionSuite.TestCases.HN.HnLgoinTest.TC_Hn_login' failed: OpenQA.Selenium.InvalidSelectorException : Unable to locate an element with the xpath expression .//td[contains(@class,'label') and contains(.,'SOID:')]/following-sibling::td because of the following error:
[object Error]
    at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
    at OpenQA.Selenium.Remote.RemoteWebElement.FindElement(String mechanism, String value)
    at OpenQA.Selenium.Remote.RemoteWebElement.FindElementByXPath(String xpath)
    at OpenQA.Selenium.By.<>c__DisplayClasse.<XPath>b__c(ISearchContext context)
    at OpenQA.Selenium.By.FindElement(ISearchContext context)
    at OpenQA.Selenium.Remote.RemoteWebElement.FindElement(By by)
0 passed, 1 failed, 0 skipped, took 39.33 seconds (NUnit 2.5.10).

Tried:

  1. lowering the the security level in "Internet Options"

Cannot find any elements in Selenium using Internet Explorer Driver

2. Added registry like below (Changed value of "iexplore.exe" from 0 to 1)

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InternetExplorer\Main\FeatureControl\FEATURE_DISABLE_INTERNAL_SECURITY_MANAGER

Registry

but no luck. Any idea or pointer how to resolve this. Thanks in advance.

Upvotes: 0

Views: 2197

Answers (1)

Tetora
Tetora

Reputation: 433

Xpaths are notorious for not working well in Internet Explorer. Try using CSS Selectors. Also, is it necessary to use IE? Chrome and Firefox are optimal for Selenium.

Upvotes: 1

Related Questions