XPath: Using Text
XPath Text():
This keyword is used to create expressions for XPath in Selenium when one has a text defined in an HTML tag and wishes to identify elements within the text.
This is useful when the other attribute values change dynamically and no substantial part of the attribute value can be selected with either the Starts-with or Contains functions.
In the examples below, the text on the button is used to identify the element. Two instances of the examples are used - one where the text is exactly matched, and one where the text is partially matched using the Contains function.
Example 1: XPath= //button[text()='Signup for Free']
Example 2: XPath= //button[contains(text(),'Signup' )]