unambiguous XPath expression
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
unambiguous XPath expression
Hi,
does anybody can explain that
'RuntimeError: unambiguous XPath expression:'
Thanks
does anybody can explain that
'RuntimeError: unambiguous XPath expression:'
Thanks
- Tech Support
- Posts: 4947
- Joined: Tue Sep 20, 2005 7:25 pm
- Contact:
Re: unambiguous XPath expression
Can you please post a test macro that triggers this error?
-
- Posts: 22
- Joined: Mon Apr 14, 2008 2:23 pm
Re: unambiguous XPath expression
Hi,
I guess you use new XPATH parameter for TAG command. The error appears when the result of XPath evaluation contains more than one element. For example on this web page http://www.iopus.com/imacros/demo/v6/f1/form.asp the following XPath expression
results into three 'td' elements and you should specify the expression further, e.g.
would select the second 'td'.
Denis
I guess you use new XPATH parameter for TAG command. The error appears when the result of XPath evaluation contains more than one element. For example on this web page http://www.iopus.com/imacros/demo/v6/f1/form.asp the following XPath expression
Code: Select all
id('TestForm')/div/center/table/tbody/tr[3]/td
Code: Select all
id('TestForm')/div/center/table/tbody/tr[3]/td[2]
Denis
Re: unambiguous XPath expression
Hello,
I see this thread is a bit older (found it through the XPATH Wiki page), but I'm having basically the same problem:
The following xpath expression creates a runtime error (ambiguous XPath expression), but I can't see what's wrong with it. It should return exactly one element:
Context: my website is an online shop, it contains several product lists (<div class="list-products">) and each of those contains several product links (<a>). This should return the first product link listed on the current page.
Any help appreciated.
I see this thread is a bit older (found it through the XPATH Wiki page), but I'm having basically the same problem:
The following xpath expression creates a runtime error (ambiguous XPath expression), but I can't see what's wrong with it. It should return exactly one element:
Code: Select all
TAG XPATH="//*[@class='list-products'][1]/a[1]"
Any help appreciated.

Re: unambiguous XPath expression
Hi connox !
It won't be easy to help without the html page. If all your div element don't have the same parent node, your expression will probably return to you the first div element for each different parent node, not only the first one.
The extension XPath Checker (https://addons.mozilla.org/fr/firefox/a ... h-checker/) will help you to see the list of all elements returned by your xpath expression so you you'll probably understand where your expression is ambiguous.
This extension is very helpful for me when i work with xpath to target some elements with iMacros.
Hope this help.
Skippyto.
It won't be easy to help without the html page. If all your div element don't have the same parent node, your expression will probably return to you the first div element for each different parent node, not only the first one.
The extension XPath Checker (https://addons.mozilla.org/fr/firefox/a ... h-checker/) will help you to see the list of all elements returned by your xpath expression so you you'll probably understand where your expression is ambiguous.
This extension is very helpful for me when i work with xpath to target some elements with iMacros.
Hope this help.
Skippyto.
Re: unambiguous XPath expression
Thanks for the tip with the XPath Checker extension, it's really useful!
I found the problem, //*[@class='list-products'][1] actually returns multiple nodes. I didn't think this was possible, but now I know. (The XSLT processor I usually work with behaves differently.)
Edit:
Is this really the intended behaviour?
As far as I know, this:
should NOT be the same as this:
But unfortunately, the iMacro xpath parser (and also the XPath Checker extension) work this way...
I think multiple predicates should be evaluated one after another, looking at the nodes defined by the previous predicate as a new nodeset, independent from the nodes' positions in the source DOM.
Edit2:
I solved the problem like this:
This returns the first <a> node in the first <div class="list-products">
But its not really an elegant solition imho
I found the problem, //*[@class='list-products'][1] actually returns multiple nodes. I didn't think this was possible, but now I know. (The XSLT processor I usually work with behaves differently.)
Edit:
Is this really the intended behaviour?
As far as I know, this:
Code: Select all
//Example[@foo = 'bar'][1]
should NOT be the same as this:
Code: Select all
//Example[@foo = 'bar' and position() = 1]
I think multiple predicates should be evaluated one after another, looking at the nodes defined by the previous predicate as a new nodeset, independent from the nodes' positions in the source DOM.
Edit2:
I solved the problem like this:
Code: Select all
//*[@class='list-products' and not(preceding::*[@class='list-products'])]/a[1]
But its not really an elegant solition imho
