Selenium and iframe Selenium and iframe selenium selenium

Selenium and iframe


I'm guessing you are using Selenium 1.0. Have you looked at Selenium 2.0 and WebDriver. I found the following and it worked for me:

Q: How do I type into a contentEditable iframe? A: Assuming that the iframe is named "foo":

driver.switchTo().frame("foo");WebElement editable = driver.switchTo().activeElement(); editable.sendKeys("Your text here"); 

Sometimes this doesn't work, and this is because the iframe doesn't have any content. On Firefox you can execute the following before "sendKeys":

((JavascriptExecutor) driver).executeScript("document.body.innerHTML = '<br>'"); 

This is needed because the iframe has no content by default: there's nothing to send keyboard input to. This method call inserts an empty tag, which sets everything up nicely.

Remember to switch out of the frame once you're done (as all further interactions will be with this specific frame):

driver.switchTo().defaultContent();

I found this on http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions


Use driver.switchTo().defaultContent(); first then do your operation