Question

I am having issues executing and xpath function in Internet Explorer 10. It works perfectly with Firefox and even Chrome, but with IE is failing. I need to search the following error message:

We cannot find this car, please click on "I don't know my car reg" above

The problem with this message is the double quotes and the quote on the don't.

Is impossible to use:

//span[@id='id']//*[text()='We cannot find this car, please click on "I don't know my car reg" above']

or

//span[@id='id']//*[text()="We cannot find this car, please click on "I don't know my car reg" above"]

So i tried this:

//span[@id='id']//*[text()=concat('We cannot find this car, please click on "I don',"'",'t know my car reg" above')]'

The concat function works perfectly in chrome and fiferox but in IE i got the following exception:

org.openqa.selenium.InvalidSelectorException: The xpath expression '//span[@id='quoteForm:registrationLookupPart:m1']//*[text()=concat('We cannot find this car, please click on "I don',"'",'t know my car reg" above')]' cannot be evaluated or does notresult in a WebElement (WARNING: The server did not provide any stacktrace information)

Does anyone know why Selenium IE driver throws this exception?

It looks like the concat function or does not exists for IE or does not work the same way. Would this be true?

Thanks a lot

Was it helpful?

Solution

IE provides no native xpath implementation so selenium has to provide its own and it may well be that this is one of the cases it falls down on. The general recommendation is to never use xpath if you do not have to and instead use css selectors as this work much faster. I am not sure this is possible for you have not posted the html.

OTHER TIPS

A couple of options:

Use a partial text match within your XPath:

//*[contains(text(), "We cannot find this car, please click on")]

Find the element by class name:

findElement.ByClass("rich-message-label");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top