2014-03-26 45 views
1

下面是HTML代碼,我試圖爲表格內的用戶名文本框做一個XPath表達式。爲什麼我的XPath表達式「無法定位元素」?

我嘗試下面的表達式:

  1. 遍歷表://table[@id='Login:LoginScreen:LoginDV']
  2. 接觸到的用戶名://input[@id='Login:LoginScreen:LoginDV:password']
  3. 要達到按鈕登錄://div/div[2]/div/table/tbody/tr/td/table/tbody/tr[4]/td[5]/a/span[2]

我收到以下錯誤消息:

找不到元素:

{"method":"xpath","selector":"//input[@id='Login:LoginScreen:LoginDV:username']"‌​} 

我很新的XPath。我正在閱讀谷歌的內容,並嘗試從我的閱讀中瞭解到的內容。

<div id="mainContent"> 
<div id="Login" class="content"> 
<div id="Login:LoginScreen:ttlBar" class="screentitle"> 
<input id="Login:LoginScreen:_msgs" type="hidden" name="Login:LoginScreen:_msgs"/> 
<span id="Login:LoginScreen:_msgs_msgs"/> 
<div id="Login:LoginScreen:0" class="info">The submitted user name/password is invalid.</div> 
<table id="Login:LoginScreen:LoginDV" class="dv "> 
<tbody> 
<tr> 
<td valign="top"> 
<table id="Login:LoginScreen:LoginDV:0" class="dvColumn" border="0" cellspacing="0" cellpadding="0"> 
<tbody> 
<tr> 
<td class="empty-cell"> 
<img height="1px" width="1px" border="0" src="images/trans_pixel.gif"/> 
</td> 
<td class="empty-cell"> 
<img height="1px" width="1px" border="0" src="images/trans_pixel.gif"/> 
</td> 
<td class="inputLabel"> 
<span>User name</span> 
</td> 
<td class="empty-cell"> 
<img height="1px" width="1px" border="0" src="images/trans_pixel.gif"/> 
</td> 
<td class="inputValue"> 
<input id="Login:LoginScreen:LoginDV:username" class="textBox" type="text" contenteditable="true" onblur="EventHandlers.onBlur(event)" onfocus="EventHandlers.onFocus(event)" helptext="__UseTitle__" size="20" style="text-align: left" delayonchange="false" onclick="event.cancelBubble = true;" onkeydown="DHTML.cancelBubbleIfNoAltKeyOrEnter();" onchange="if (EventHandlers.valueChanged(event, this)==false) return false;" value="" label="User name" name="Login:LoginScreen:LoginDV:username"/> 
</td> 
</tr> 
<tr> 
<tr> 
<tr> 
</tbody> 
</table> 
</td> 
</tr> 
</tbody> 
</table> 
</div> 
</div> 
</div> 
+1

你嘗試過什麼XPath表達式? –

+0

我不確定它是否只有我,但我無法在該HTML代碼段中找到任何輸入元素。 –

+0

<表ID = 「登錄:LoginScreen:LoginDV」 類= 「DV 」> <表ID = 「登錄:LoginScreen:LoginDV:0」 類= 「dvColumn」 用戶名 <輸入的ID = 「登錄:LoginScreen:LoginDV:用戶名」 類= 「textBox中」 類型= 「text」contenteditable =「true」value =「」label =「User name」name =「Login:LoginScreen:LoginDV:username」/> – Surabhi

回答

0

它看起來像實際的問題可能是畸形的XML:行30,31和32是沒有任何關閉的開放標籤。

我將您的XML複製到我的文本編輯器Notepad ++中,該文本編輯器安裝了XML Tools插件。將這三個標記更改爲<tr />後,我使用插件中的XPath表達式評估程序來嘗試原始XPath語句//input[@id='Login:LoginScreen:LoginDV:username'],並發現該節點沒有任何問題。

(我試過,包括截圖,但我的代表處是不夠高。截圖可以發現here)。

相關問題