xpath to save html element value to session variable

342 views
Skip to first unread message

greg.l...@gmail.com

unread,
Dec 19, 2012, 12:37:01 AM12/19/12
to gat...@googlegroups.com
Hi,

I am executing an http get which returns html including a hidden input element in the following format:

<input type="hidden" id="txtTestID" name="txtTestID" value="11"/>

I'd like to save the value 11 into a session variable for use in a subsequent call. I've tried:

.check(xpath("""//input[@id="txtTestID"]@value""").find.saveAs("testID"))

This doesn't seem to work, also tried without the @value. Am I doing something wrong, or is there a better way to do this? I've read that parsing html with a regular expression is a bad idea,

thanks,

Greg.

Nicolas Rémond

unread,
Dec 19, 2012, 1:09:11 AM12/19/12
to gat...@googlegroups.com
Hi,

The XPath library we rely on is currently only working for XML documents.
I would suggest you to use a CSS selector like this :
.css("#txtTestId", "value")

cheers
Nicolas

greg.l...@gmail.com

unread,
Dec 19, 2012, 5:46:30 PM12/19/12
to gat...@googlegroups.com
Thanks, the css selector worked perfectly.

I'm new to Google groups, should I mark the topic as answered and/or the reply as the best answer? If so, how is this done as it's not immediately obvious?

Greg.

Nicolas Rémond

unread,
Dec 20, 2012, 2:27:45 AM12/20/12
to gat...@googlegroups.com
Glad to hear it's working. 

Well, that's just a mailing-list, there isn't any fancy functionalities like on StackOverflow.

cheers
Nicolas
Reply all
Reply to author
Forward
0 new messages