# Locate element text with continually changing id's and classes

**URL:** <https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141>\
**Category:** SeleniumLibrary\
**Created:** [25 January 2022 13:37 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141 "2022-01-25T13:37:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![resourceful-idiot](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@resourceful-idiot](https://forum.robotframework.org/u/resourceful-idiot)\
**Post date:** [25 January 2022 13:37 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141/1 "2022-01-25T13:37:09Z")

</div>

Hi,

Am I missing an easy way to check a text value appearing at elements without using class or id.

e.g. I want to check “mytext” appears on the page at a given element:

```
<td _ngcontent-ng-cli-universal-c123="">mytext</td>

```

…below is the XPATH and script but will not work consistently as the generated HTML id or class/css are always random (but the text is always the same at this location):

```
Element Should Contain //*[@id="random_id_123"]/div/table/tbody/tr[1]/td[3] mytext

```

I don’t really want to use:

```
Page Should Contain mytext

Angular 12
Python 3.7.8
requests 2.26.0
robotframework 4.1.1
robotframework-extendedrequestslibrary 0.5.5
robotframework-pythonlibcore 3.0.0
robotframework-seleniumlibrary 5.1.3
selenium 4.0.0
urllib3 1.26.7
```

---

<div class="post-metadata">

**Author:** ![EdManlove](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/edmanlove/32/1002_2.png) [@EdManlove](https://forum.robotframework.org/u/EdManlove)\
**Post date:** [25 January 2022 13:47 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141/2 "2022-01-25T13:47:52Z")

</div>

I would search for a slightly different xpath than

`//*[@id="random_id_123"]/div/table/tbody/tr[1]/td[3]`

Just some questions I would ask … Is there some sort of stable page structure before `//*[@id="random_id_123"]`? Is there any other tables within the page?

---

<div class="post-metadata">

**Author:** ![resourceful-idiot](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@resourceful-idiot](https://forum.robotframework.org/u/resourceful-idiot)\
**Post date:** [25 January 2022 14:30 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141/3 "2022-01-25T14:30:21Z")

</div>

Hi. There are no other tables on this page and this is the same situation for all HTML other than tables where the id and css class now change every time the app loads a page. I wonder if this is a limitation of Robot Famework to work with an SPA built with Angular.

---

<div class="post-metadata">

**Author:** ![janipalsamaki](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/janipalsamaki/32/154_2.png) [@janipalsamaki](https://forum.robotframework.org/u/janipalsamaki)\
**Post date:** [25 January 2022 15:21 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141/4 "2022-01-25T15:21:57Z")

</div>

> [@resourceful-idiot](#):
>
> There are no other tables on this page

Then you could just target the `table` element and the specific row and cell?

---

<div class="post-metadata">

**Author:** ![janipalsamaki](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/janipalsamaki/32/154_2.png) [@janipalsamaki](https://forum.robotframework.org/u/janipalsamaki)\
**Post date:** [25 January 2022 15:31 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141/5 "2022-01-25T15:31:54Z")

</div>

> [@resourceful-idiot](#):
>
> I wonder if this is a limitation of Robot Famework to work with an SPA built with Angular.

It’s all HTML markup at the end of the day. The underlying markup generator implementation does not really matter. It could be Angular, React, Vue…

If you are dealing with a very dynamic web application, [Robot Framework Browser](https://marketsquare.github.io/robotframework-browser/Browser.html) could be interesting. It can automatically wait for elements to appear, etc. Less code to write compared to SeleniumLibrary in many cases.

---

<div class="post-metadata">

**Author:** ![Puistis](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/puistis/32/875_2.png) [@Puistis](https://forum.robotframework.org/u/Puistis)\
**Post date:** [30 January 2022 18:49 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141/6 "2022-01-30T18:49:09Z")

</div>

I would recommend using the “contains” function in your xpath, usually all randomly generated id’s have some part that does not change

So

//element[contains(@id,“part-of-id-that-is-allways-same”]

If it catches some secondary element just add “and not”

//element[contains(@id,“stuff”) and not(contains(@class, id, whatever,“part-thats-present-in-that-other-element”)]

And you should avoid using \*

---

<div class="post-metadata">

**Author:** ![resourceful-idiot](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@resourceful-idiot](https://forum.robotframework.org/u/resourceful-idiot)\
**Post date:** [1 February 2022 09:21 UTC](https://forum.robotframework.org/t/locate-element-text-with-continually-changing-ids-and-classes/3141/7 "2022-02-01T09:21:18Z")

</div>

Thank you thats very useful
