-1

Is It possible to find an element using xpath that has a dynamic div?

test = self.driver.find_element_by_xpath('/html/body/main[1]/div[HERE!]/div[1]/div[1]/div[2]/div[5]')

I must find this element that changes the div[HERE!] deppending of your action on the page

EDIT

Here's the outer HTML. label is the only unique part of it, and the numeric (91) is dynamic...

 <div class="group">
 <label>Tipo Benefício</label>
 <span><b class="numeric">91</b>AUXILIO DOENCA POR ACIDENTE DE TRABALHO
 </span></div>
Moises Felipe
  • 83
  • 2
  • 9

1 Answers1

1

You can use the below relative xpath to get the numeric value.

//div[@class='group']/b[@class='numeric']

Your code should be

test = self.driver.find_element_by_xpath("//div[@class='group']/b[@class='numeric']")
print(test.text)

You can access the other elements as shown below

# label => //div[@class ='group']/label
# span  => //div[@class ='group']/span

You can refer to this post to check your xpath/css locators are working as expected in chrome devtools.

supputuri
  • 13,644
  • 2
  • 21
  • 39