简体   繁体   中英

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

我是硒编码的新手,我看到几个 xpath 包含 (.,'followed by something') ., 指的是什么?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM