John Robert
John Robert

Reputation: 3

How can i select duplicate and dynamic element in selenium java

Please below same button HTML with the dynamic value I have tried to find but unable to handle this

<input data-form="#emailTemplateForm-278" type="button" value="Save" class="btnSave btn btn-default btn-yellow"  
  onclick="$(this).blur();SubmitEmailTemplateForm($(this).data('form'))">

<input data-form="#emailTemplateForm-280" type="button" value="Save" class="btnSave btn btn-default btn-yellow" 
 onclick="$(this).blur();SubmitEmailTemplateForm($(this).data('form'))">

I have created below XPath and I want to select the second one

//input
  [starts-with(@data-form,'#emailTemplateForm-') and @class='btnSave btn btn-default 
  btn-yellow' and @value='Save' and @type='button'][1]

Above one is working fine but this isn't working

//input
  [starts-with(@data-form,'#emailTemplateForm-') and @class='btnSave btn btn-default 
  btn-yellow' and @value='Save' and @type='button'][2]

Please advice thanks and waiting for your response

Please below same button HTML with the dynamic value I have tried to find but unable to handle this

PFB HTML for Elements

Upvotes: 0

Views: 594

Answers (1)

Sers
Sers

Reputation: 12255

Try locators below:

Css selectors
1. button .btnSave:nth-child(1)
2. button .btnSave:nth-child(2)

Xpath
1. button (//input[@value='Save'])[1]
2. button (//input[@value='Save'])[2]

Upvotes: 1

Related Questions