0

I am trying to find a button on a website, however this button won't always be there and there are multiple buttons that are identical in everyway. The xpath of the buttons is :

//*[@id="inspire"]/div[3]/main/div/div/div[3]/div[i]/div/div/div[2]/button/div

Where i is the i'th button. To find the correct button however I have to check the text in the first element (/div[1]) of the '/div' list before the '/button/ (where you can see '/div[2]'. This text is specific per button. And I have a specific string I'm looking for in these div[1]'s and I only need the button above which is this specific string.

(I have already checked the string is indeed on the page so the button does exist everytime I get to this step. I just need to find the button that is underneath it.)

Thanks in advance!

1
  • Update the question with the text based HTML of the element. Commented Apr 26, 2022 at 22:32

2 Answers 2

1

use xpath with text filter e.g

browser.find_element_by_xpath('//button[text()="texthere"]')
Sign up to request clarification or add additional context in comments.

Comments

0

You can use elems =elem.find_elements_by_id("id" ) Then use loop to seperate all elements that have same locator .

Comments

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.