Need Help With QA Automation?

Work with our skilled full stack experts to improve your software quality, accelerate testing cycles, and enhance overall performance.

Hire Full Stack Developers

Support On Demand!

I’m trying to use contains function on selenium and trying to do a certain action if that specific text exists and click on it.

How to use contains function with driver.find_element(). So far I tried:

testData = "Test"
if testData in element.text:
        driver.find_element(By.LINK_TEXT, contains({testData})).click() 
else:
    print(f"The element does not contain the text: {testData}.")

Related Q&A