0

My code:

<input type="text"
       placeholder="Label"
       class="other[] form-control"
       name="projectsurvey[1438590696705][choosekey][1438590696705][]" 
       value="">

Where name projectsurvey[changes][choosekey][changes]

I'm using this to try to find the item: xpath("//*[starts-with(@name,'projectsurvey','choosekey')])

The firebug xpath is showing like this :

*[@id="choice1438590696705"]/div/div[1]/div[2]/div/input

and the firebug xpath changes:

[@id="choice143......."]/div/div[1]/div[2]/div/input

How do I find this element by xpath

Is there any other way to find this element

  • Can you paste some more html content – QAMember Aug 3 '15 at 13:28
  • Everything in name="" is getting changed? – Gaurav Khanna Aug 4 '15 at 12:15
1

You can use 'contains' :

//input[contains(@name, 'projectsurvey[143') and contains(@name, 'choosekey][143')]
  • @saiviswanath - if the answer solved your problem, please mark it as accepted, then delete your comment. – Kate Paulk Jun 5 '17 at 11:41
0

I had more complicated situation, even 'contains' was not enough. I got list of all elements of type (find by TAG_NAME), then looped over the list to find elements of interest by parts of id and class name. I had even to find matching pairs of elements with parts of name generated dynamically.

Because of flexible list processing in Python, it was not too hard. I try to avoid XPATH: real programming language like Python, which I already know, gives me more flexibility and is easier to maintain, than cryptic and obscure XPATH expressions. YMMV.

0

Depending on how many more similar elements you have on the page, an xpath like the following may do what you need:

//input[@type='text'][contains(@class,'form-control')][contains(@name,'projectsurvey')]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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