tags:

views:

304

answers:

2

Hi

I am looking to write an XPath query to return the full element ID from a partial ID that I have constructed. Does anyone know how I could do this? From the following HTML (I have cut this down to remove work specific content) I am looking to extract f41_txtResponse from putting f41_txt into my query.

<input id="f41_txtResponse" class="GTTextField BGLQSTextField2 txtResponse"  value="asdasdadfgasdfg" name="f41_txtResponse" title="" tabindex="21"/>

Cheers

+2  A: 

You can use contains to select the element:

//*[contains(@id, 'f41_txt')]
Thomas Jung
With the way we are generating the webpage this is retrieving everything where I am just looking for the element ID.
//*[contains(@id, 'f41_txt')] will select a list of tags you have to iterate over it and select the id attribute for each of them. You can use count(//*[contains(@id, 'f41_txt')]) to get the total number.
Thomas Jung
Thats not the best way to do this. I have answered my own question though with the help of you answer.
praise the lord, thanks to thomas jung i remembered that you always need the @ sign to find atrributes. duh.
esryl
+1  A: 

Thanks to Thomas Jung I have been able to figure this out. If I use:

//*[contains(./@id, 'f41_txt')]/@id

This will return just the ID I am looking for. Thank you for the help.

Be aware that this can fail. You might want to use `//*[starts-with(@id, 'f41_txt')]/@id` instead.
Tomalak