I am running a test nightly via Jenkins. About 95% of the time it passes. But occasionally it is failing doing this:
driver.findElement(By.xpath("//div[contains(@id, 'stage')]/div[contains(@class, 'tabMenu')]/span[contains(@class, 'menuItem') and contains(text(),'Employer')]"))
with an org.openqa.selenium.InvalidSelectorException. Note: this almost always works.
So I debug using Eclipse and Java and Selenium. Again, I had to run the test about 30 times before getting this error.
I am using Selenium and IE. IE does not have good debugging so using Eclipse Debug Shell I write the page source to a file, rename the file to an html file and edit with Chrome. In the inspect window I do a search for
//div[contains(@id, 'stage')]/div[contains(@class, 'tabMenu')]/span[contains(@class, 'menuItem') and contains(text(),'Employer')]
and it finds it and highlights it. When I from debug shell do a
driver.findElement(By.xpath("//div[contains(@id, 'stage')]/div[contains(@class, 'tabMenu')]/span[contains(@class, 'menuItem') and contains(text(),'Employer')]"))
I get the
org.openqa.selenium.InvalidSelectorException:Unable to locate an element ... because of the following error:
[object Error] (WARNING: The server did not provide any stacktrace information)
So I thought I would just get all the divs and get their IDs:
driver.findElement(By.xpath("//div"))
and I get
org.openqa.selenium.InvalidSelectorException: Unable to locate an element with the xpath expression //div because of the following error:
[object Error] (WARNING: The server did not provide any stacktrace information)
so OK. I try driver.findElement(By.xpath("//*")) and still get the InvalidSelectorException
so "//*" would have to find elements. And even if it didn't, shouldn't it return something like a NoSuchElementException rathe than an InvalidSelectorException? Anyone know what is happening? I did a search to find the meaning of InvalidSelectorException and found usage but not really a definition.
So I guess I have two questions: 1. why aren't any elements (even "//*") being found, and 2. Shouldn't it be returning NoSuchElementException and not InvalidSelectorExmaple?