Reputation: 23
<div class="slds-show" data-aura-rendered-by="10155:0">
<div class="footer" data-aura-rendered-by="10156:0">
<div class="slds-grid slds-grid--align-end slds-m-top--large" data-aura-rendered-by="10157:0">
<div class="slds-show" data-aura-rendered-by="10158:0">
<button class="slds-button slds-button--neutral slds-m-left--small" data-aura-rendered-by="10159:0">Cancel</button>
<button class="slds-button slds-button--neutral slds-m-left--small" data-aura-rendered-by="10161:0">Save & New</button>
<button class="slds-button slds-button--brand slds-m-left--small" data-aura-rendered-by="10163:0">Save</button>
</div>
</div>
</div>
This is part of page, on which I will have to click on Save button. Button is not unique and I need to find it throu class attribute from first div (slds-show), or
Can somebody tell me, why this xpath is not finding this element?
//button[parent::div[@class='slds-show'][@class='slds-button slds-button--brand slds-m-left--small']]
I've also try with ancestor, text instead of class and results is the same. Element is not found via Firefox console
Upvotes: 2
Views: 578
Reputation: 193308
To click on Save button once finding it through class attribute from first div (slds-show) you can use a much simpler and effective xpath as follows :
//div[@class='slds-show']/button[@class='slds-button slds-button--brand slds-m-left--small']
Note : The class attribute
slds-button--brand
is unique for the Save button.
Upvotes: 1
Reputation: 1463
An xpath can easily get too complex, you can also try something like this:
//button[text()='Cancel']
//button[text()='Save & New']
//button[text()='Save']
These will return the exact buttons you need. If you're looking for a specific ancestor, include it in your xpath:
//div[@class="slds-show"]//button[text()='Save & New']
Upvotes: 0
Reputation: 5347
You can try the following xpaths.
//*[@class="slds-show"]/button[text()="Save"]
or
//*[class="slds-show"]/button[@class="slds-button slds-button--brand slds-m-left--small"]
Upvotes: 0
Reputation: 52685
Try to update your expression as below:
//button[parent::div[@class='slds-show'] and @class='slds-button slds-button--brand slds-m-left--small']
Note that predicate [@class='slds-button slds-button--brand slds-m-left--small']
in your XPath intend to test @class
value of parent div
, but not target button
Upvotes: 0