2010-06-04 60 views
0

在重播爲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> 

回答

0

你已經寫了無效的XPath查詢。

應該

//div[@ id='composebox']/div[@id='toid']/textarea[@id='to' and @name='to']

+0

謝謝大衛,它工作。 – mgeorge 2010-06-04 14:17:49

0

<textarea>有一個id屬性,它應該是唯一的,所以你僅僅to第一定位應該工作。執行selenium命令時,該元素可能不存在或不可見。我想提出以下建議:

waitForVisible | id=to | 60000 
type | id=to | [email protected] 

如果你的元素具有唯一的ID,你需要使用XPath,您只需要相對於同一個id屬性最接近的元素。

+0

謝謝戴夫,文本區域被選中,但沒有數據被輸入到它,但下面的聲明工作。 waitForVisible | id = to | 60000 類型| // textarea的[@ '到' ID = | [email protected] – mgeorge 2010-06-05 05:04:19