Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't find Web element with xpath using driver.findElement(By.xpath());

I tried to find the link on a page to click:

<a id="folder0" class="js-folder icon-wrap icon-wrap_left menu__item__link menu__item__link_act menu__item__link_unread" href="/messages/inbox" rel="history">
    <span class="js-folder-b-unread js-folder-unread menu__item__link__qnt">7</span>
    <i class="js-folder-ico icon icon_left icon_folders icon_inbox_act"></i>
    <span class="menu__item__link__text menu__item__link__text_linear">Input</span>
</a>

Java code:

driver.findElement(By.xpath(".//*[@id='folder0']/span[2]")).click();

But the driver can't locate the element:

 org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='folder0']/span[2]"}
like image 541
Bilow Yuriy Avatar asked Dec 11 '22 11:12

Bilow Yuriy


1 Answers

Thank you for all answers. I found solution to my problem. The last command was command which was linked with IFrame

WebElement editorFrame = driver.findElement(By.cssSelector("#sentmsgcomposeEditor_ifr"));
   driver.switchTo().frame(editorFrame);

   WebElement body1 = driver.findElement(By.tagName("body"));
   body1.sendKeys(Keys.CONTROL + "a"); 

So i was in IFrame actually because of it i couldn't find any element. I performed following command:

 driver.switchTo().defaultContent();

After that it is possible to find locators.

like image 111
Bilow Yuriy Avatar answered Dec 22 '22 02:12

Bilow Yuriy