2017-08-11 21 views
-1

下面是代碼。有人可以幫助我單獨標識3個文本框,而不使用索引。如何識別第一,第二和第三個文本框而不使用索引(例如[1]) - xpath,selenium

<html> 
    <head> 
     <title>test</title> 
     <script></script> 
    </head> 
    <body> 
     name: 
     <input type="text"/> 
     <br/> 
     name: 
     <input type="text"/> 
     <br/> 
     name: 
     <input type="text"/> 
     <div>testdiv</div> 
    </body> 
</html> 
+0

你所有的3個元素是相同的所以它只能夠間接使用像'// input [1]'這樣的索引,如果你可以使用像'// input [last()]這樣的函數' - 它會找到最後一個輸入標籤' // input [last() - 1]' - 它會找到第二個輸入標籤或者使用'position()' - '// input [position()= 1]'等等 – NarendraR

+2

您的業務需求是什麼?爲什麼你想避免索引? – DebanjanB

+0

顯示你如何試圖解決你的問題 – Andersson

回答

0

你可以試試下面的表達式匹配每個input

對於第一種:

//input[not(preceding-sibling::input)] 

對於第二:

//input[preceding-sibling::input and following-sibling::input] 

第三:

//input[not(following-sibling::input)] 
相關問題