1

I need to access this element:

<input id ="combo-1105-inputWrap">

The 4 digits in the xpath are autogenerated per browser session. I need to find that particular xpath and key in the data.

I have tried to use a regular expression in my xpath but I am not able to make this work.

//*[contains(id,'combo-1[0-9]{3}') and ends-with(id,'-inputWrap')]

How can I reliably access this element?

5
  • 1
    stackoverflow.com/questions/405060/… gives more detail on using regular expressions in Xpath.
    – Kate Paulk
    Nov 7, 2017 at 12:35
  • Try using "//input[contains(@id,'combo-')]".It might work.
    – shanila
    Nov 7, 2017 at 17:20
  • Problem with the "//input[contains(@id,'combo-')]" is that it matchs with all the UI elements present on the page contains the id combo-. But I need to identify only the particular Input box with the combination of "combo-1105-inputWrap" Nov 8, 2017 at 7:01
  • Can you add some more html so we can make it unique using parent elements
    – NarendraR
    Nov 8, 2017 at 9:08
  • provide some more HTML. then you can use xpath axes or selenium 4 relative operators.
    – a Learner
    Dec 26, 2021 at 17:39

1 Answer 1

4

You can use some wild cards in cssSelecter to locate the same. Try below css Selector :

input[id^='combo-'][id$='-inputWrap']

For further clarification see this :-

input[id^='id_prefix_']

input[id$='_id_suffix']

input[id*='id_pattern']

You can find more information here.

1
  • 1
    I found this one more helpful in understanding the Regular Expressions Jun 8, 2018 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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