Handling iframe via RemoteDriver

46 views
Skip to first unread message

Glib Shevchuk

unread,
Apr 18, 2014, 9:13:04 AM4/18/14
to seleniu...@googlegroups.com

Hi guys,

I can't sendKeys to webElement in iframe. I got page with iframe with <p> in it.

       driver.switchTo().frame(1);

       Then 
       WebElement frameInput = driver.switchTo().activeElement();
        frameInput.sendKeys("Test");

       or 

       driver.findElement(By.cssSelector("p")).sendKeys("Test");

      Sometimes test fails due to invisibility of element (WebDriverWait.until(visibilityof()) doesn't help) and sometimes test pass, but text doesn't appear in element.

     I tried Actions and ((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<br>'"), but got
java.lang.ClassCastException: com.sun.proxy.$Proxy11 cannot be cast to org.openqa.selenium.JavascriptExecutor
and java.lang.ClassCastException: com.sun.proxy.$Proxy11 cannot be cast to org.openqa.selenium.interactions.HasInputDevices at org.openqa.selenium.interactions.Actions.<init>

Using selenium-server 2.41.0 and FF 28

Thanks in advance!
 

Shawn McCarthy

unread,
Apr 18, 2014, 6:51:33 PM4/18/14
to seleniu...@googlegroups.com
Why not get the frame by the WebElement? Like this:

WebElement iFrame = driver.findElement(By.id("myIFrameId"));
driver.switchTo.frame(iFrame);

WebElement paragraph = driver.findElement(By.tagName("p"));
paragraph.sendKeys("Enter Text Here");

This may not be exact, as I wrote it freehand.
Reply all
Reply to author
Forward
0 new messages