Xpath syntax to find an element

Hello! I request your help to know how to identify an element by xpath using the content of the HTML element instead of the ID of the element

example:

In the image you can see how using the syntax xpath;
//div[@aria-labelledby=‘ui-id-38’]//span[contains(.,“Accept”)]
I can find the content of the popup window, the which has an ID:19.

[image]

The IDs of this website change constantly, so I want to try to identify that same element but using the text it contains, since this is not a variable.

Is it possible?

@Yoshi You can identify an element using the text it contains. find an example syntax below
//div[contains(text(), ‘example text’)]

just use tag name and mention the text it contains using above syntax

1 Like

@Yoshi,

did you try to copy and use Full Xpath of the button?

1 Like

Yes, I’ve tried using Full Xpath but since ID is changing constantly, is not a option

Can you copy and paste the full XPath you tried to use? Usually the full XPath looks like this:

/html/body/section/div/div[1]

Sometimes the numbers change when the element is dynamic, but an asterisc [*] instead of the number might be helpful.

/html/body/section/div/div[*]

1 Like