1

I have following html snippet:

<button><span>Next</span></button>

I want to locate this button and I am using the following:

driver.find_element_by_xpath("//button[@span[.='Next']]")

Also used:

driver.find_element_by_xpath("//button//span[.='Next']")

but this locates the span instead of the button :(

But no luck with this. Does anyone know what is the correct way for the same?

2 Answers 2

3

Try this XPATH to locate button based on child span text content

"//button[span='Next']"
Sign up to request clarification or add additional context in comments.

Comments

1

Try this xpath:

driver.find_element_by_xpath("//span[text()='Next']//parent::button")

1 Comment

what you just shared locates the span and not the button which results in is not clickable.

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.