未在IDE中执行的XPath语句
在重播为yahoomail页面创建的脚本时,我遇到了问题。要在“到”文本字段中输入值的XPath语句不起作用。以下是我使用的XPath语句。未在IDE中执行的XPath语句
在第一次尝试,我用
<tr>
<td>type</td>
<td>to</td>
<td>[email protected]</td>
</tr>
第二个尝试是这种说法
<tr>
<td>type</td>
<td>//div[@id= 'toid']/textarea[@id= 'to'][@name= 'to']</td>
<td>[email protected]</td>
</tr>
第三次尝试在此
<tr>
<td>typeKeysAndWait</td>
<td>//div[@ id= 'composebox']/div[@id= 'toid']/textarea[@id= 'to'][@name= 'to']</td>
<td>[email protected]</td>
</tr>
结果就像
[error] Element //div[@ id= 'composebox']/div[@id= 'toid']/textarea[@id= 'to'][@name= 'to'] not found
在以前的尝试中获得了类似的结果。 后来当我试图
<tr>
<td>type</td>
<td>css=textarea.txtfield</td>
<td>[email protected]</td>
</tr>
邮件ID被输入到文本字段,脚本工作perfectly.what可能是reason.Any的想法?
我加入XPath语句
<div id="composepage">
<div id="composebox" class="roundcorner">
<div id="errorContainer"/>
<input type="hidden" name="defFromAddress" value="[email protected]"/>
<div class="fields row">
</div>
<div id="toid" class="row">
<label id="compose_to" for="to">
</label>
<textarea id="to" class="txtfield" name="to" autocomplete="off" tabindex="1" style="overflow: hidden; height: 19px;"/>
</div>
你已经写了无效的XPath查询。
应该
//div[@ id='composebox']/div[@id='toid']/textarea[@id='to' and @name='to']
的<textarea>
有一个id属性,它应该是唯一的,所以你仅仅to
第一定位应该工作。执行selenium命令时,该元素可能不存在或不可见。我想提出以下建议:
waitForVisible | id=to | 60000
type | id=to | [email protected]
如果你的元素具有唯一的ID,你需要使用XPath,您只需要相对于同一个id属性最接近的元素。
谢谢戴夫,文本区域被选中,但没有数据被输入到它,但下面的声明工作。 waitForVisible | id = to | 60000 类型| // textarea的[@ '到' ID = | [email protected] – mgeorge 2010-06-05 05:04:19
谢谢大卫,它工作。 – mgeorge 2010-06-04 14:17:49