-1

I am trying to locate this tag with CSS selector inner text

<a href="/introduction-to-selenium.html">1) Introduction</a>

I have used the xpath:

a.contains("1) Introduction")

But its not working. Can anyone help me?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Spartan
  • 31
  • 4
  • `a.contains("")` is not `xpath` or `css selector`. You can't use `css selector` to locate by text in any case. – Guy Aug 20 '19 at 10:17

3 Answers3

0

The selector you're using is not xpath one, the correct xpath selector would be like this:

//a[contains(string(), "1) Introduction")]
Adam Kosmala
  • 925
  • 6
  • 9
0

To locate the element you can use either of the following Locator Strategies:

  • linkText:

    1) Introduction
    
  • partialLinkText:

    Introduction
    
  • cssSelector:

    a[href^='/introduction-to-selenium']
    
  • xpath:

    //a[starts-with(@href, '/introduction-to-selenium') and contains(., 'Introduction')]
    

Outro

selenium.common.exceptions.InvalidSelectorException with “span:contains('string')”

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

you can use contains also in xpath to identify the tag.

eg : //a[contains(text(),'Introduction')]

There should not be multiple "Introduction" in the page.

Raj
  • 21
  • 6