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.
    – BoltClock
    CommentedApr 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.

2
  • No, it's a problem with the selector syntax.
    – BoltClock
    CommentedApr 30, 2013 at 8:15
  • 2
    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.
    – Yi Zeng
    CommentedApr 30, 2013 at 10:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.