I have a scenario where I 1st iframe (i.e parent iframe) which has one button on it and clicking on it another iframe gets open (child iframe). I am able to switch to Parent iframe but when I click on the button and tries to interact with Child iframe I'm not able to do it. Can you suggest what should be the better approach to get this type of scenarios working?

Here is my Script:

public class Iframe {
    public static void main (String []args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", Constants.Chrome_Driver);

        WebDriver driver = new ChromeDriver();


        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


        Actions action = new Actions(driver);
        driver.findElement(By.linkText("New Private Message")).click();
        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id=\"jform_message_imgmanager\"]"))).click();
        new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[contains(@src,'&plugin=imgmanager')]")));
        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"browser-actions\"]/a[@id=\"help\"]"))).click();
        new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@id=\"mce_inlinepopups_50_ifr\"]")));
        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"imgmanager.insert\"]/i[@class=\"icon-file\"]"))).click();



Error in getting:

Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for frame to be available: By.xpath: //iframe[@id="mce_inlinepopups_50_ifr"] (tried for 20 second(s) with 500 milliseconds interval)
    at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:271)
    at testScripts.Iframe.main(Iframe.java:53)
Caused by: org.openqa.selenium.NoSuchElementException: Cannot locate an element using By.xpath: //iframe[@id="mce_inlinepopups_50_ifr"]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T15:15:08.936Z'
System info: host: 'vowellt4', ip: '', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-24-generic', java.version: '1.8.0_171'
Driver info: driver.version: unknown
    at org.openqa.selenium.support.ui.ExpectedConditions.lambda$findElement$0(ExpectedConditions.java:896)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at org.openqa.selenium.support.ui.ExpectedConditions.findElement(ExpectedConditions.java:895)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$000(ExpectedConditions.java:44)
    at org.openqa.selenium.support.ui.ExpectedConditions$17.apply(ExpectedConditions.java:517)
    at org.openqa.selenium.support.ui.ExpectedConditions$17.apply(ExpectedConditions.java:513)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)
    ... 1 more
  • From parent iframe switch to child iframe just like you switched to the parent iframe from the current top level browsing context. Please share the code and execution log/ stacktrace. Aug 1, 2018 at 8:34
  • 1
    It's better to edit your question and add what have your tried, where you gets stuck, and the exception you received. Aug 1, 2018 at 9:51
  • @BharatMane: I have updated my question. Please have a look and let me know. Thanks in advance!
    – Kaustubh
    Aug 2, 2018 at 16:42

2 Answers 2


Since you have parent frame and child frame,first switch into the parent frame and click the button which is present in Parent frame.Then Switch into the child frame so that you can interact with the child frame.

  • Thanks! I have tried the same but something is wrong and I'm getting stucked. Have updated my question. Please have a look. Thanks in advance!
    – Kaustubh
    Aug 2, 2018 at 16:43

First of all - there is no need to create a new WebDriverWait object if the timeout does not change, instead just store a reference to it.

Second thing - you should not mix Implicit and Explicit waits together, as their implementation might cause unpredictable wait times. Explicit and Implicit Waits

Are you sure about the hierarchy of iframes? Can you post a screenshot from Chrome devtools console with the iframes listed on it? Like this:

chrome devtools iframes

If hierarchy is not an issue, check if the 'parent' iframe does not reload when the new iframe is created - if that is the case you need to switch back to default content:


after the button is pressed and then again switch to parent and child.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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