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!

Akzy
  • 1,817
  • 1
  • 7
  • 19
Rap
  • 1

2 Answers2

1

use xpath with text filter e.g

browser.find_element_by_xpath('//button[text()="texthere"]')
Aadi
  • 31
  • 8
0

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