0

Example HTML below. I want to locate the elements which contains the text Person Attributes and Age.

<div id="ext-gen210" class="x-tool x-tool-toggle"></div>
<span id="ext-gen214" class="x-panel-header-text">Person Attributes</span>
</div>
<div id="ext-comp-1071" class=" DDView ListView" style="height: auto;">
   <p class="dragItem "><i class="icon-Gen"></i>Age</p>
</div>

Note: I am looking for a solution without using xpath or id or className as they might change with every new release of my website.

I tried to locate them using

'name' --> By.name("Person Attributes") and By.name("Age") but both failed.

Saifur
  • 16,081
  • 6
  • 49
  • 73
bpk
  • 313
  • 2
  • 6
  • 20

1 Answers1

2

By.name would check for the name attribute. What you need is to check the text of an element using By.xpath:

By.xpath('//div[span/text() = "Person Attributes"]')

Or, you can also check that an id element starts with ext-gen:

By.xpath('//div[starts-with(@id, "ext-gen")]')
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195