How to find an element that contains specific text in Selenium

You can use the XPath contains() and text() functions to do this.

Java

driver.findElement(By.xpath("//*[contains(text(), 'My Button')]");

Python

driver.find_element_by_xpath("//*[contains(text(), 'My Button')]")

C#

driver.FindElement(By.XPath(("//*[contains(text(), 'My Button')]"));