0

enter image description here

Hello, I am trying to click the button 'Test Here' using selenium in Python via chrome. I have no clue what it is not working. My code is shared below...

driver.find_element_by_xpath("//*[contains(text(), 'Test Here')]").click()

2 Answers 2

1

Click the button and not the span.

Add /parent::button would fix your xpath.

Sign up to request clarification or add additional context in comments.

4 Comments

I'm sorry, very new to using selenium. Could you give me an exact example?
Oh just copy it and put it at the end of your xpath. It moves up 1 level to the button tag.
//span[.='Test Here']/parent::button
Like the above.
0

You can try the find_element_by_link_text method, like this:

driver.find_element_by_link_text("Test Here").click()

2 Comments

This is the error that I got.... :( selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Test Here} (Session info: chrome=88.0.4324.150)
@ghost Try adding the line "driver.implicitly_wait(5)" before the "driver.find_element_by_link_text("Test Here").click()" line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.