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

梦想与她 提交于 2020-01-25 02:47:47

问题


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


回答1:


The . character within the xpath 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:

  • How to locate the button element using Selenium through Python
  • While fetching all links,Ignore logout link from the loop and continue navigation in selenium java
  • How does dot(.) in xpath to take multiple form in identifying an element and matching a text


来源:https://stackoverflow.com/questions/57976490/what-does-contains-some-text-refers-to-within-xpath-used-in-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!