Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

type into iframe in selenium

I need to type data into an iframe. I referred to

Typing in a IFrame with Selenium IDE

but selenium.selectFrame(<xpath>) returns: Element not found error and no css has been defined for the iframe.

Using firebug:

<iframe frameborder="0" allowtransparency="true" tabindex="0" src="" title="Rich text editor, templateWizardCKEditor1, press ALT 0 for help." style="width: 100%; height: 100%;"/>

What could be a solution for this?

like image 267
aradhak Avatar asked Jan 17 '23 01:01

aradhak


2 Answers

I found a solution for the same...

driver.switchTo().frame("ext-gen298");
WebElement editable = driver.switchTo().activeElement();
editable.sendKeys("Your text here");
driver.switchTo().defaultContent();

Ref: http://code.google.com/p/seleniumwikiFrequentlyAskedQuestions#Q:_How_do_I_type_into_a_contentEditable_iframe?

like image 84
Somesh Avatar answered Jan 25 '23 22:01

Somesh


That just means you used some bad xpath.

selenium.selectFrame("xpath=//iframe[contains(@title,'Rich text editor')]");

This should work. It selects the iframe based on an xpath expression that looks for an iframe which title attribute contains "Rich text editor".

For more xpaths, see XPath v1.0 on w3.org and XPath v2.0 on w3.org - only for some browsers.

By the way, the iframe can be selected by css selectors, too, even if it has no css assigned. The selector can select any element based on its position in tree hierarchy and it's attributes - similar to XPath. To learn about css selector, try The w3 again or wikipedia

like image 29
Petr Janeček Avatar answered Jan 25 '23 22:01

Petr Janeček