0

I'm using Selenium WebDriver 3.11.0 and Chrome 66 and trying to retrieve element using following css selectors which are based on text of the element -

1.

 WebElement element = driver.findElement(By.cssSelector("h3:contains('File Downloader')"));

2

 WebElement element = driver.findElement(By.cssSelector("h3[text='File Downloader']"));

3

 WebElement element = driver.findElement(By.cssSelector("h3[innertext='File Downloader']"));

It gives following error for #1:

org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified

while #2 and #2 are unable to locate element(NoSuchElementException)

Following is the HTML for the element -

<h3>File Downloader</h3>

Is it something that css is not supporting retrieving element based on text? I want to understand what has changed now because in many posts, I can see all above three ways were recommended for retrieving elements based on text in css selector.

Alpha
  • 13,320
  • 27
  • 96
  • 163
  • @cruisepandey Can you shed some light why you feel its not a duplicate? Have you read the question carefully enough to interpret OP's actual error **org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified** which is exact duplicate of the marked discussion [selenium.common.exceptions.InvalidSelectorException with “span:contains('string')"](https://stackoverflow.com/questions/47883572/selenium-common-exceptions-invalidselectorexception-with-spancontainsstring) with **2** distinct Answers where both were helpful to community members? – undetected Selenium Jun 06 '18 at 11:31
  • 2
    @DebanjanB : Guy has given the answer in XPath , whereas your answer does not give the desire output as OP intended in this question. – cruisepandey Jun 06 '18 at 11:36
  • 1
    If the answers from the duplicate(s) don't fully address your question, please edit your question above to tell us why. It will then be sent for others to review if the added information makes it suitable for re-opening. – Samuel Liew Jun 07 '18 at 10:46

0 Answers0