0

I have tried to use CSS Selector with contains() in selenium webdriver, but I'm facing NullPointerException.

Can someone please help?

private static final String testcode = "p:contains('Notes')";

public String getTextCode(String codes) throws Exception {
    String jc = driver.findElement(By.cssSelector(codes)).getText();
    return jc;
}
Tom
  • 1,387
  • 3
  • 19
  • 30
Prabhu
  • 394
  • 1
  • 7
  • 23
  • 1
    `contains()` seems to be a JQuery function. Please see this similar question: https://stackoverflow.com/questions/5441680/css-selector-based-on-element-text – Tom Sep 25 '17 at 13:13
  • W3C css locator not support contains(), selenium use native css lcoator supported by browser which describled by the W3C. you mentioned contains() should be supported by JQuery. – yong Sep 25 '17 at 13:37

1 Answers1

1

According to the specifications, it is not supported. You can use XPath.