Page 1 of 1

xpath extract multiple answer

Posted: Sat Aug 06, 2016 1:50 pm
by DDon
Hi,


I'm using Firefox 48 with imacro VERSION BUILD=8970419

Windows 10

I'm trying to extract the element in the XML file. However, the xpath have multiple result. Is there anyway that we can extract all the result match with the xpath and save each element in each variable?

I got the code TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy" EXTRACT=TXT and get the error

RuntimeError: ambiguous XPath expression: /Prefilling2016/PrivateHealthInsurance/PHIPolicies/PHIPolicy, line 3 (Error code: -982)

Tried to google but still can't find the solution. Thank you.

Re: xpath extract multiple answer

Posted: Sat Aug 06, 2016 6:06 pm
by chivracq
DDon wrote:Hi,


I'm using

Code: Select all

Firefox 48 with imacro VERSION BUILD=8970419
Windows 10
I'm trying to extract the element in the XML file. However, the xpath have multiple result. Is there anyway that we can extract all the result match with the xpath and save each element in each variable?

I got the code

Code: Select all

TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy" EXTRACT=TXT
and get the error
RuntimeError: ambiguous XPath expression: /Prefilling2016/PrivateHealthInsurance/PHIPolicies/PHIPolicy, line 3 (Error code: -982)
Tried to google but still can't find the solution. Thank you.
There is probably a way using "Standard" TAG Mode with 'POS=1' / 'POS=2' etc...

You have the 'SEARCH' Command as well.

I don't use 'XPATH' nor 'SEARCH' but you can "mimic" those Commands by first extracting some higher HTML Element containing all your Elements that you want to extract and then use 'EVAL()' + 'split()' to isolate the Data that you want to keep...

Post the URL of your Page or upload your XML File to the Thread (zipped, Max 256Kb) if you don't come up by yourself...

Re: xpath extract multiple answer

Posted: Tue Aug 09, 2016 6:25 am
by iimfun
If the number of multiple elements is known a priori, just specify them directly

Code: Select all

TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy[1]" EXTRACT=TXT
TAG XPATH="/PrivateHealthInsurance/PHIPolicies/PHIPolicy[2]" EXTRACT=TXT
...

Re: xpath extract multiple answer

Posted: Thu Aug 11, 2016 11:59 am
by DDon
Thank you your post, this help a lot and I can extract what I want now.

I haven't learned any programing language so I can never fully understand the val function of the iMacro,

1. How can I eval the extract text from 1963-11-09 to 09/11/1963?

2. Is there any solution that we save fully page to .aspx but not html? I found no solution after google a few days :(

I appreciate everyone support in the forums. Thank you.

Re: xpath extract multiple answer

Posted: Thu Aug 11, 2016 2:23 pm
by iimfun
1. How can I eval the extract text from 1963-11-09 to 09/11/1963?
Here is a code for that

Code: Select all

SET !EXTRACT EVAL("'{{!EXTRACT}}'.split('-').reverse().join('/');")