0

Here is my code

driver.findElements(By.cssSelector(".main-menu a:contains(\"Access Menu\")")).size()

is throwing exception

org.openqa.selenium.InvalidElementStateException: invalid element state: SyntaxError: DOM Exception 12

Same css value is working in jquery i.e. $(".main-menu a:contains(\"Access Menu\")").size()

1
  • 3
    :contains() is not a CSS selector. That DOM exception is being thrown by querySelectorAll() which I suspect is what WebDriver is using, bypassing jQuery altogether. Commented Apr 30, 2013 at 8:16

1 Answer 1

1

Is it possible to have your html of your <a> ?

Because the DOM Exception 12 is generally a trouble with your html syntax. Maybe the jQuery don't care about but the WebDriver throws an exception.

Edit (after BoltClock intervention):

There is another solution instead of using the CssSelector, the xpath !

"//*[@class='.main-menu']/a[contains(text(),'Access Menu')]"

Tell me what's up.

Sign up to request clarification or add additional context in comments.

2 Comments

No, it's a problem with the selector syntax.
Shouldn't the first part be //*[@class='main-menu'] instead of //*[@class='.main-menu']? Also, using //*[contains(@class, 'main-menu')] would be better, as we don't have the DOM, we can't promise main-menu is the only class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.