I'm trying to access iFrame

    <iframe id="frame1" style="width: 100%; height: 100%; display: block;" tabindex="100">
    <head xmlns="http://www.w3.org/1999/xhtml">
    <body id="tiny1" contenteditable="true" onload="window.parent.get('frame1').onLoad.dispatch();">

And I want to sendKeys() to the body with id=tinymce. But when I tried to switchTo().frame, it does not work.

My Java code:

public void enterArea(String object, String content){
        String driverWindows = driver.toString();
        String driverIFrame = driver.toString();
        WebElement contentTextArea = (new WebDriverWait(driver, 3))

The two driverWindows and driverIFrame always return the same string, it means the web driver has not switched, right?

Could you help me access to elements? Please do let me know if require any further details.

2 Answers 2

  1. Use driver.getWindowHandle() to see if the focus has switched to another window. This method returns a unique id for every frame.

  2. Use By.Id("frame1") to locate by id, this is much cleaner than XPath.

  3. Using sendKeys is equivalent to typing text on the keyboard. But you're sending this to a <p> element; as far as I know this will result is nothing. You need an editable control to type text into.


Use driver.switchTo().frame(frameName)

Your Answer

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

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