I am unable to locate a frame inside an iframe. I have attached the screenshot of the html page.Html screenshot

I am able to locate iframe 'content' by xpath //div[@id='pageContentDiv']//iframe which I verified in chrome and my code is working.

WebElement frame1 = driver.findElement(By.xpath("//div[@id='pageContentDiv']//iframe"));

but unable to locate the frame 'detailsDisplay'.I tried //div[@id='pageContentDiv']//iframe//frame[@name='detailsDisplay'] but unable to locate in chrome. My motive is to locate the 'Part Details' link element inside the 'detailsDisplay' frame. Full code.

public WebDriver createPart() {

try {

    driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);
    Select dropCountry = new Select(driver.findElement(By.id("txtNewLocation")));
    driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);

    //driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
    //driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);     
    String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
    driver.findElement(By.xpath("//li[@class='icon-button add']/span")).click();

    driver.findElement(By.xpath("//label[starts-with(text(),'Create Part...')]")).click();
    driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);       
    String subWindowHandler = null;     
    Set<String> handles = driver.getWindowHandles(); // get all window handles
    Iterator<String> iterator = handles.iterator();
    while (iterator.hasNext()){
        subWindowHandler = iterator.next();

    WebDriverWait wait = new WebDriverWait(driver, 10);

    WebElement element = driver.findElement(By.xpath("//select[@id='Type-Field']//following-sibling::div//div//input"));




    driver.manage().timeouts().implicitlyWait(70, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(70, TimeUnit.SECONDS);



    driver.findElement(By.xpath("//a[@title='Part Details']")).click();

} catch (InterruptedException e) {
    // TODO Auto-generated catch block
return driver;


I am adding 2 screenshots. In the first screenshot I am able to locate the iframe 'content'. In the second screenshot, I am unable to locate the 'detailsDisplay' frame (HTML code is not getting highlighted) by xpath //div[@id='pageContentDiv']//iframe//frame[@name='detailsDisplay']

screenshot 1 screenshot 2

Is there anything issue with the html tag and document tags in the code ? I am struggling with this issue quite a longtime. Please suggest some solutions.

  • Share the full code starting from how you switch iframe finishing with how you locate your link element. – Alexey R. May 29 '18 at 9:51
  • I have added full code. – kiran kumar May 29 '18 at 10:12
  • @kiran kumar i am facing a similar issue. can you please share how u resolved this issue? – Ayisha Apr 12 '19 at 7:07

If your code has nested frames, first switch to the parent frame. Then switch from the parent frame to the inner child frame where you want to locate the element.

Once you switched to the child frame, locate the element which you want.

//a[text()='Part Details'];
  • I tried facing unable to locate error. – kiran kumar May 29 '18 at 9:10
  • Have you tried with this xpath - //a[text()='Part Details'] – shanila May 29 '18 at 9:25
  • Unable to locate element: {"method":"xpath","selector":"//a[text()='Part Details']"} error occured – kiran kumar May 29 '18 at 10:25

1.Use the following code to switch into the frame:

driver.switchTo.frame(content); //now you have switched into the frame

2.Then you need to switch into the details display frame using the below code:


3.Then access the part details using the below xpath:

//a[contains(text(), 'Part Details')]
  • I tried these beforehand. But nothing is working out. I am able to switch to 'detailsDisplay' frame through code but facing Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//a[@title='Part Details']"} while trying to locate th element. In chrome I can locate content frame. but unable to locate 'detailsDisplay' frame. Inside detailsDisplay frame html code is included in #document. Maybe it has something to do with that. – kiran kumar May 29 '18 at 9:09
  • Your xpath seems to be attribute based and //a[contains(text(), 'Part Details')] seems to be a text based. please try this xpath and let me know still you are facing issues. – Prasanna venkatesh May 29 '18 at 9:29
  • Unable to locate element: {"method":"xpath","selector":"//a[text()='Part Details']"} error occured. – kiran kumar May 29 '18 at 10:25
  • Give browser.sleep or proper wait commands after switching into the frame and try to execute – Prasanna venkatesh May 29 '18 at 10:41
  • Tried that too. Its failing again. Firstly, I am unable to locate the detailsDisplay frame in chrome by xpath. I think if we can resolve that we can resolve this issue. – kiran kumar May 29 '18 at 10:51

I don't know if it works for python but that was how I solved this problem in Java:

the switchTo().frame() method returns a WebDriver that is focused on the targeted iframe. We can reach the sub Iframe using this webDriver like :

WebDriver subDriver = webDriver.switchTo().frame("iFrameName").switchTo().frame("subIFrameName");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.