1

This question already has an answer here:

In my application one form is there having 10 elements.All elements are having same ID but with different number at the end.I want to locate all the elements.Can anyone give me xpath please.

@FindBy(xpath=".//*[@id='ext-gen1095']")
WebElement period_type;
@FindBy(xpath=".//*[@id='ext-gen1472']")
WebElement months;
@FindBy(xpath=".//*[@id='ext-gen1097']")
WebElement period_start;
@FindBy(xpath=".//*[@id='ext-gen1464']")
WebElement submit;
@FindBy(xpath=".//*[@id='ext-gen1482']")
WebElement clear;

marked as duplicate by Bharat Mane, NarendraC, Alexey R., alecxe Jun 14 '18 at 12:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

1.Use starts-with function.

In your case XPath's ID attribute, ext-gen1 part remains same every time.

 //*[starts-with(@id,'ext-gen1')]

2.Look for other attributes which are not changing continuously for Ex. class, name, type, tabindex etc and use and function in between the XPath.

//*[starts-with(@id,'ext-gen1') and contains(@name,'----')] 
  • How can I use same xpath to locate all the elements in the form ?All attributes are same for all the elements only number is changing in ID – Jeevan Jun 12 '18 at 13:29
  • Can you add your html code, so that it will be clearly understood the situation. – Bharat Mane Jun 12 '18 at 14:20
  • 1
    @Jeevan why do you need the same xpath to locate all the elements on the form? – Alexey R. Jun 13 '18 at 10:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.