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.

WebElement period_type;
WebElement months;
WebElement period_start;
WebElement submit;
WebElement clear;

1 Answer 1


1.Use starts-with function.

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


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
    Commented Jun 12, 2018 at 13:29
  • Can you add your html code, so that it will be clearly understood the situation.
    – Bharat Mane
    Commented Jun 12, 2018 at 14:20
  • 1
    @Jeevan why do you need the same xpath to locate all the elements on the form?
    – Alexey R.
    Commented Jun 13, 2018 at 10:39

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