# Can reference to element with Selenium command despite element being present

**URL:** <https://forum.robotframework.org/t/can-reference-to-element-with-selenium-command-despite-element-being-present/8211>\
**Category:** Robot Framework\
**Created:** [27 December 2024 15:22 UTC](https://forum.robotframework.org/t/can-reference-to-element-with-selenium-command-despite-element-being-present/8211 "2024-12-27T15:22:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mael](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@Mael](https://forum.robotframework.org/u/Mael)\
**Post date:** [27 December 2024 15:22 UTC](https://forum.robotframework.org/t/can-reference-to-element-with-selenium-command-despite-element-being-present/8211/1 "2024-12-27T15:22:17Z")

</div>

I am being stuck for quite some time on this problem so I finally decide to ask help to this forum!

There is an element on the webpage that I know for sure exist. The following command executed in the console of the browser opened by the test return a DOM element:

$x(“//\*[@id=‘menu-gestion-centres-activites’]//span”)  
returns this:  
[span.p-menuitem-text.ng-tns-c1818545701-6.ng-star-inserted]

I can find the element too by iterating over the WebElements of the page with a for loop over the result of the GetElements command (All elements are logged by id and I can see the element is in the page).

But Selenium can’t find the element in the page. Despite using 20s wait, command like Wait Until Page Contains Element and Wait Until Element Is Visible never find the element by either its id, or using xpath.

I tried with  
id=menu-gestion-centres-activites and  
xpath=//\*[@id=‘menu-gestion-centres-activites’]//span

I don’t know what to try anymore. Any suggestion?

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [27 December 2024 16:21 UTC](https://forum.robotframework.org/t/can-reference-to-element-with-selenium-command-despite-element-being-present/8211/2 "2024-12-27T16:21:52Z")

</div>

Hi,

Is your element eventually in an Iframe or a shadow-dom?  
That would explain why you find it, but can’t interact with it.

Regards  
Charlie

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [27 December 2024 23:32 UTC](https://forum.robotframework.org/t/can-reference-to-element-with-selenium-command-despite-element-being-present/8211/3 "2024-12-27T23:32:31Z")

</div>

Would it be possible that the element is not infact in the dom _if_ certain event hasn’t happened, like opening a menu or scrolling containing element to view or whatnot ?

Eg, while others have asked about iframe’s, at least from info you have given there could be changes in the DOM when you run `$x()` vs what your selenium session sees. Basing this on observation that app feels like it’s angular based (ng in the returned span selector). What im trying to point out that the code that actually adds the menu items could be lazy-loaded code.
