2009-10-09 104 views
0

我有一個網頁的HTML下面的代碼片段:Selenium中的xPath - 我做錯了什麼?

... 
<tbody id="c_scopePane4_tbody"> 
<tr id="c_scopePane4_tr_header"> 
... 
</tr> 
</tbody> 
... 

現在,我試圖從內硒指定<tr>標籤使用XPath表達式。這是我嘗試:

//tr[@id='c_scopePane4_tr_header'] 

這告訴我

[error] locator not found: //tr[@id='c_scopePane4_tr_header'], error = Error: 
Element //tr[@id='c_scopePane4_tr_header'] not found 

但是,如果我改變XPath表達式:

//*[@id='c_scopePane4_tr_header'] 

...然後它的作品。是什麼賦予了?

回答

3

這對我來說是一樣的片段。也許你的HTML中有其他東西會導致問題?你有多個<tr>(或任何其他元素)具有相同的ID?

由於ID(意思是唯一的),您應該可以放心地使用第二個XPath表達式。另外,您可以使用以下,但一定要與xpath=所以先於你的定位是硒知道定位器的類型,您使用的是:

xpath=id('c_scopePane4_tr_header') 

另外,如果你只是想選擇<tr>元素,那麼你也可以使用下列中的一個:

  • c_scopePane4_tr_header
  • 標識符= c_scopePane4_tr_header
  • ID = c_scopePane4_tr_header
0

備用CSS風格定位:

css=tr#c_scopePane4_tr_header 

或DOM風格:

dom=document.getElementById("c_scopePane4_tr_header")