如何查找元素的xpath或CSS,哪个类名对于其他元素是相同的

时间:2013-07-10 11:47:59

标签: xpath selenium-webdriver

帮我找到一个元素的xpath,我想在第二个[2]中找到@ class =“tipN button greenB”,它有@ class =“middleNav”

    <div id="rightSide"> 
<div class="topNav"> 
<style type="text/css"> 
<div class="resp"> 
<div class="titleArea"> 
<div class="wrapper"> 
<div class="pageTitle"> 
<div class="middleNav" data-bind="visible: showAllButtons" style="display: none;"> 
<a id="saveformtop" class="tipN button greenB" data-bind="click: SaveForm, visible: showGridButtons" original-title="Save Staff data" href="#" style="margin: 5px; display: none;" novalidate="novalidate"> 
<a class="tipN button greenB" original-title="Save Staff data" href="#" style="margin: 5px;" data-bind="click: SaveRestrictions, visible: showRestriction"> 
<a id="cancelbtntop" class="tipN button redB" original-title="Cancel all edits" data-bind="click:CancelForm, visible: showGridButtons" style="margin: 5px; display: none;"> 
<a class="tipN button redB" original-title="Cancel all edits" data-bind="click: CancelRestriction, visible: showRestriction" style="margin: 5px;"> 
<div class="clear"> </div> 
</div> 
<div class="middleNav" data-bind="visible: !showAllButtons()" style=""> 
<a id="cancelbtntop" class="tipN button redB" original-title="Cancel all edits" data-bind="click:CancelForm, visible: showGridButtons" style="margin: 5px; display: none;"> 
<img class="icon" src="../../content/css/images/icons/light/arrowLeft.png" alt=""> 
<span>Back</span> 
</a> 
<a class="tipN button greenB" original-title="Save Staff data" href="#" style="margin: 5px;" data-bind="click: SaveRestrictions, visible: showRestriction"> 
<img class="icon" src="../../content/css/images/icons/light/check.png" alt=""> 
<span>Save</span> 
</a> 
<a class="tipN button redB" original-title="Cancel all edits" data-bind="click: CancelRestriction, visible: showRestriction" style="margin: 5px;"> 
<div class="clear"> </div> 
</div> 
</div> 
</div> 
<div class="clear"> </div> 
<div class="line"> </div> 
<div> 
</div> 
<div id="footer"> 
<style> 
<div id="leftsidehide" style="display: none;"> 
</div>

3 个答案:

答案 0 :(得分:1)

我不确定完全理解你的问题。但是我会从理解中做到这一点:

//*[contains(@class, 'middleNav')][2]/*[contains(@class, 'tipN button greenB')]

答案 1 :(得分:0)

希望我理解正确:

(//div[@class="middleNav"])[2]/a[@class="tipN button greenB"]

答案 2 :(得分:0)

如果适用于您,请尝试以下操作:

//div[@class='middleNav']//a[@class='tipN button greenB']