type into iframe in selenium

…衆ロ難τιáo~ 提交于 2019-12-05 14:45:29
Somesh

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?

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

Rick Baker
  1. Select the frame first,
  2. Then click it to separate the header information (WSYWG) from the text area,
  3. Then focus on the text area (tinymce)
  4. Then send your text to populate the field (we have 2 examples to show different objects that work)
  5. Then select Window back to default window (null)

Here is what I used that worked:

<td>selectFrame</td>
<td>xpath=//*[contains (@id, 'mce_0_ifr')]</td>
<td></td>

<td>click</td>
<td>xpath=//*[contains (@id, 'tinymce')]</td>
<td></td>

<td>focus</td>
<td>xpath=//*[contains (@id, 'tinymce')]</td>
<td></td>

<td>sendKeys</td>
<td>xpath=//*[contains (@id, 'tinymce')]</td>
<td>I Typed in an iFrame!!!</td>

<td>sendKeys</td>
<td>css=body#tinymce.mceContentBody</td>
<td>0</td>

<td>selectWindow</td>
<td>null</td>
<td></td>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!