XPATH selection with node text content. Super useful. Python Selenium.

Not sure how I missed this selection method. It’s one of the most useful methods of selecting an element. By its text. So if you have something like :

<span class="important text">Hello There</span>

The xpath for this element could be :

//span[@class='important text' and text()='Hello There']

In the code this could be something like:

self.driver.find_element_by_xpath(Locators.HelloThere).click()

The text element, I believe, is good as even if the backend code changes there is less likelihood of front end text changing and confusing the end user. The test has more staying power.