2014-04-23 97 views
0

形象我想點擊圖片<img> w.r.t在td標籤中提到的「TM100」。請任何人都可以給我XPath。如何找到XPath來點擊具有相同的名稱

我在選擇圖像時遇到問題。因爲所有圖像都具有相同的xpath。

<tr> 
<td> 
<div id='xxx' class='avatar_standalone' ...> 
<div class ='yyy'> 
<div class ='zzz'> 
<a oncontextmenu="return false" href="javascript:void(0)" onclick="xxx('MINE|XX0172', '2');> 
<img class="newassetIcon assetIcon linkable" src="https://xxxx/servlet/servlet.ImageServer?id=015d00000020ZaWAAU&oid=00Dd0000000eu33&lastMod=1377179945000"/> 
</a> 
<span class="imgData" style="display: none;">MINE|XX0172</span> 
</div> 
</div> 
</div> 
</td> 
<td style="border: 1px solid rgb(211, 211, 211);">XX0172</td> 
<td style="border: 1px solid rgb(211, 211, 211); text-align: center;">6073.7</td> 
<td style="border: 1px solid rgb(211, 211, 211);">TM2</td> 
</tr> 

<tr> 
<td> 
<div id='xxx' class='avatar_standalone' ...> 
<div class ='yyy'> 
<div class ='zzz'> 
<a oncontextmenu="return false" href="javascript:void(0)" onclick="xxx('MINE|XX0172', '2');> 
<img class="newassetIcon assetIcon linkable" src="https://xxxx/servlet/servlet.ImageServer?id=015d00000020ZaWAAU&oid=00Dd0000000eu33&lastMod=1377179945000"/> 
</a> 
<span class="imgData" style="display: none;">MINE|XX0172</span> 
</div> 
</div> 
</div> 
</td> 
<td style="border: 1px solid rgb(211, 211, 211);">XX0172</td> 
<td style="border: 1px solid rgb(211, 211, 211); text-align: center;">1073.7</td> 
<td style="border: 1px solid rgb(211, 211, 211);">TM3</td> 
</tr> 

<tr> 
<td> 
<div id='xxx' class='avatar_standalone' ...> 
<div class ='yyy'> 
<div class ='zzz'> 
<a oncontextmenu="return false" href="javascript:void(0)" onclick="xxx('MINE|XX0172', '2');> 
<img class="newassetIcon assetIcon linkable" src="https://xxxx/servlet/servlet.ImageServer?id=015d00000020ZaWAAU&oid=00Dd0000000eu33&lastMod=1377179945000"/> 
</a> 
<span class="imgData" style="display: none;">MINE|XX0172</span> 
</div> 
</div> 
</div> 
</td> 
<td style="border: 1px solid rgb(211, 211, 211);">XX0172</td> 
<td style="border: 1px solid rgb(211, 211, 211); text-align: center;">8073.7</td> 
<td style="border: 1px solid rgb(211, 211, 211);">TM100</td> 
</tr> 

回答

0

請檢查這一項,可能這會爲你工作:

//tr[descendant::td[contains(text(),'TM100')]]//img[@class='newassetIcon assetIcon linkable'] 

我已經測試使用這個上面的代碼:

//tr[descendant::td[contains(text(),'TM100')]]//td[contains(text(),'XX0172')] 
+0

謝謝..其工作 – Thyagu

0

如果你想獲得img元素,如果你想點擊你可能想選擇a的圖像,你可以使用下面的XPath

//tr[td = 'TM100']/div[@id = 'xxx']/div[@class = 'yyy']/div[@class = 'zzz']/a/img 

,所以以下工作:

//tr[td = 'TM100']/div[@id = 'xxx']/div[@class = 'yyy']/div[@class = 'zzz']/a 
+0

謝謝您的回答。但我得到的錯誤是:org.openqa.selenium.NoSuchElementException: – Thyagu

+0

如何驗證XPath是正確與否的Chrome瀏覽器?有沒有可用的工具? – Thyagu

+0

@Thyagu:[評估和驗證在Chrome開發者工具的XPath/CSS選擇](http://yizeng.me/2014/03/23/evaluate-and-validate-xpath-css-selectors-in-chrome-developer-工具/) –

相關問題