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 contentQAMember– QAMember2015年08月03日 13:28:17 +00:00Commented Aug 3, 2015 at 13:28
-
Everything in name="" is getting changed?Gaurav Khanna– Gaurav Khanna2015年08月04日 12:15:23 +00:00Commented Aug 4, 2015 at 12:15
3 Answers 3
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– Kate Paulk2017年06月05日 11:41:29 +00:00Commented Jun 5, 2017 at 11:41
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.
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')]