2012-03-28 58 views
4

我需要输入数据到iframe。我提到在硒中输入iframe

Typing in a IFrame with Selenium IDE

selenium.selectFrame(<xpath>)回报:Element not found error并没有CSS已经为iframe定义。

使用Firebug:

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

可能是什么解决办法?

回答

3

这只是意味着你使用了一些不好的xpath。

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

这应该有效。它根据xpath表达式选择iframe,该表达式查找iframe的哪个title属性包含“Rich Text Editor”。

欲了解更多xpaths,请参阅XPath v1.0 on w3.orgXPath v2.0 on w3.org - only for some browsers

顺便说一下,iframe也可以由CSS选择器选择,即使它没有分配CSS。选择器可以根据树的层次结构中的位置选择任何元素,它的属性 - 类似于XPath。要了解CSS选择器,尝试The w3 againwikipedia

+1

selenium.selectFrame(“xpath = // iframe [contains(@ title,'Rich Text Editor')]”); (“xpath = // iframe [包含(@标题,'富文本编辑器')]”,tag); 但找到元素未找到错误。所以我尝试 selenium.selectFrame(“xpath = // iframe [包含(@标题,'富文本编辑器,templateWizardCKEditor3,按ALT 0帮助。')]”); selenium.type(“xpath = // iframe [包含(@标题,'富文本编辑器,templateWizardCKEditor3,按ALT 0帮助。')]”,tag);但没用。 – aradhak 2012-03-29 07:16:21

+0

那么,如果你想正确写入iframe,那可能是一个问题。在第一个'selectFrame()'之后,你可以尝试[this method](http://selenium.googlecode.com/svn/trunk/docs/api/java/com/thoughtworks/selenium/Selenium.html#getWhetherThisFrameMatchFrameExpression%28java .lang.String,%20java.lang.String%29)。写入可编辑的iframe是非常棘手的,可以[使用WebDriver](http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions#Q:_How_do_I_type_into_a_contentEditable_iframe?)或通过一些类似于那里显示的JavaScript的JavaScript来完成猜测。 – 2012-03-29 08:52:13

+0

...因为当你执行'selectFrame()'时,你基本上已经把这个帧作为你的新根节点。这意味着如果你想写入框架,你需要调用'selenium.type(“xpath = /”,tag);'...这也可能实际上工作!试试看:) – 2012-03-29 08:54:27

0
  1. 选择框架的第一个,
  2. 然后单击它的头信息(WSYWG)从文本区分开,
  3. 然后专注于文本区域(TinyMCE的)
  4. 然后发送文本填充字段(我们有2个例子表明,不同的工作对象)
  5. 然后选择Window回默认的窗口(空)

这是我使用的曾经工作过:

<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>