0

I am having difficulties with webdriver switching its focus to an iframe I have tried all standard webdriver commands including below without much luck ... i really appreciate if some one could help with this ?

driver.switchTo().frame(driver.findElement(By.tagName("iframe")));

Here is my html code:

<iframe class="x-component x-fit-item x-component-default" frameborder="0" src="/portal/page?libraryContext=7934fbba34c3d5bb965bcc33ff3a45acef04ff13d6e700ed7cc64a926f62db8e&amp;siteId=LT1&amp;menu=wm.config#wm.config.warehouse.warehouse////" name="1stPage:wm.config.warehouse.warehouse;Menu:wm.config;Ctx:7934fbba34c3d5bb965bcc33ff3a45acef04ff13d6e700ed7cc64a926f62db8e-1515619700794" data-lifecycle-participant="true" id="jdaIFrame-1026" style="margin: 0px; width: 1319px; height: 924px;"></iframe>
JeffC
  • 22,180
  • 5
  • 32
  • 55
  • what do you mean by difficulties? what is the issue? – nilesh Jan 11 '18 at 00:19
  • What's wrong with using the ID or any number of other attributes? Or you can switch by index. Have you tried any of these? – JeffC Jan 11 '18 at 19:50
  • Possible duplicate of [How to handle iframe in Selenium WebDriver using java](https://stackoverflow.com/questions/9942928/how-to-handle-iframe-in-selenium-webdriver-using-java) – JeffC Jan 11 '18 at 19:52
  • webdriver is returning no element found exception when i tried id or name or index ... it works now by using below xpath – Anil Kumar Nagisetty Jan 12 '18 at 15:25

1 Answers1

0

As per the HTML you have provided you can use the following line of code to switch to the iframe :

driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='x-component x-fit-item x-component-default' and starts-with(@id,'jdaIFrame-') and contains(@src,'/portal/page?libraryContext=')]")));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352