1

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;
3

1 Answer 1

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,'----')] 
3
  • 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.