ALISON HARTLEY
ALISON HARTLEY

Reputation: 15

What does contains(., 'some text') refers to within xpath used in Selenium

I am new to selenium coding, and I am seeing several xpaths that contain (.,'followed by something') what does the ., refer to?

Upvotes: 1

Views: 173

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193088

The . character within the is the short form of text()

As an example if an WebElement is represented within the DOM Tree as:

<span>Use this payment method</span>

Effective Locator Strategies will be:

  • xpath 1:

    //span[text()='Use this payment method']
    
  • xpath 2:

    //span[contains(., 'Use this payment method')]
    

Reference

You can find a couple of relevant discussions in:

Upvotes: 1

Related Questions