1

I am using Selenium for HCI tests, but Selenium couldn't find an element that was visible, intrigued, I searched it and came to the conclusion that, the element is visible but not present in the DOM.

I may be mistaken (likely), but it's what it seems to be for me.


I have a website with an element, Parcourir :
Element "Parcourir"

When I click on it, I can see this div element: Navigateur de médias

Here is the problem now, There is an element Bibliothèque at the top of the window, when I open the Browser Developer Tools, and inspect it, I find its id and XPath, the element HTML code is below:

<a href="#media-tab-media_default--media_browser_1"
data-tabid="media_default--media_browser_1" title="Bibliothèque" class="ui-tabs-anchor"
role="presentation" tabindex="-1" id="ui-id-3">
    Bibliothèque
</a>

But when I tried to download the DOM, just like its said in this answer: How can I dump the entire Web DOM in its current state in Chrome?.

I can't find the above element in the DOM, I have an element that I can see in my Browser, which is not present in the DOM. That's may be why selenium give me the Exception:

Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[@id='ui-id-3']

Hamza Ince
  • 604
  • 17
  • 46

2 Answers2

2

As element is inside iframe you have to switch to it first:

The syntax for switch to frame is

driver.switchTo().frame(id);

If you have multiple iframes and there is no id find each iframes uniquely as you do for other elements , using any other attributes like Id,class etc of the specific iframe

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class=\"class\"]")));

Now remember to switch outside the frame to interact with elements outside the iframe again.

  driver.switchTo().defaultContent();
Hamza Ince
  • 604
  • 17
  • 46
PDHide
  • 18,113
  • 2
  • 31
  • 46
0

As mentioned by @PDHide, the problem was that the element was inside a frame, I just switched to the frame, like below:

webdriver.switchTo().frame(frameId);

And it worked.

Hamza Ince
  • 604
  • 17
  • 46