XPATH QUERY

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
Post Reply
footyfacts
Posts: 11
Joined: Tue Jul 02, 2013 11:48 am

XPATH QUERY

Post by footyfacts » Sun Aug 27, 2017 4:00 am

Firefox 52.2.1 (32-bit)
Imacros VERSION BUILD=9030808
Windows XPsp2

They changed the page on me and XPATH is a bit obtuse for an old man like me
I now get the product code and product price extract twice

My code (courtesy of others who have helped previously)

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]" Extract=Txt <== This ends up with 553919553919
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]" Extract=Txt <== this ends up with $98.60$98.60
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt
SAVEAS TYPE=EXTRACT FOLDER=F:\PC-Stuff\Sendmail\DanPages FILE=ALM_EXT.CSV


SAMPLE TR DATA

<tr bgcolor='#ECECFF'>
<td><a href="javascript:launchWindow('History?ProductId=553919');" title="CRWN SEAL 750ML" class="phtip">553919</a> <input type="hidden"
name="ProductId" value="553919"/></td>

<td>CRWN SEAL MOSC 750ML</td>

<td align="center">6</td>

<td align="center">6</td>

<td align="right">$ 98.60<input type="hidden" name="UniversalDealIncGST" value="0.00" /></td>

<td align="center"><a title="No Current Allowance" class="alwtip">$ 0</a></td>

<td align="center"><font face="courier new" size="3"><tt><b>&nbsp;</b></tt></font><input type="text" name="OrderCtnQty" value=""
class="formfield" onfocus="resetKeepAliveTime();" maxlength="3" size="5"/></td>

<td align="center"><input type="hidden" name="OrderUnitQty" value=""/>&nbsp;</td>

<td><a href="javascript:launchWindow('/alm/user/LineCalculator?ProductId=553919&PackQty=6&WetRate=29.0&
BaseCostPriceExGST=69.49','popup',600,400);" title="View Line Calculator" class="tip"><img src="media/images/icons/inner_calculator.gif"
align="absmiddle" border="0" hspace="1" null></a> <input type="hidden" name="UnitPriceExGST" value="98.60"/></td>

<td align="center"><INPUT type="hidden" name="IsAddProduct" value="false"><input type="checkbox" name="IsAddProduct"/></td>

</tr>
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: XPATH QUERY

Post by iimfun » Mon Aug 28, 2017 6:32 am

Maybe the input elements cause troubles. What about this way?

Code: Select all

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
or

Code: Select all

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/input" Extract=Txt
and

Code: Select all

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/input" Extract=Txt
If it doesn't work then you should use the EVAL command.
footyfacts
Posts: 11
Joined: Tue Jul 02, 2013 11:48 am

Re: XPATH QUERY

Post by footyfacts » Sat Sep 02, 2017 10:55 am

Thanks

both /a or /input work for the first cell however in the interim they changed the page slightly
and the 5th element now contains a <nobr>

However whilst the following works when these is no BOLD element it does not work when there is a BOLD
(The BOLD is only present when a product is onl special, the NOBR is always present)

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/nobr" Extract=Txt


<td align="right"><b><nobr>&nbsp;$ 53.37&nbsp;</nobr></b><input type="hidden" name="UniversalDealIncGST" value="0.00" /></td>

<td align="right"><nobr>&nbsp;$ 53.37&nbsp;</nobr><input type="hidden" name="UniversalDealIncGST" value="0.00" /> </td>

GregF
footyfacts
Posts: 11
Joined: Tue Jul 02, 2013 11:48 am

Re: XPATH QUERY

Post by footyfacts » Sat Sep 02, 2017 11:58 pm

My solution isn't elegant however the following does solve my problem
although it is probably going to break when they change things on me again
I do have the "safety" in knowing that change is not often because it is
not an e-commerce site it is just the wholesaler/retailer ordering

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
set !LOOP 1
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/b[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/nobr[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt

I would still like to know however why the NOBR fails when there is a <b><nobr> tag pair
surely the test is irrelevant to the precedence of the tags and indeed why the original
extracts the $$ amount twice (I know why the 1st tag did as it is there twice)

gregF
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: XPATH QUERY

Post by chivracq » Sun Sep 03, 2017 2:32 am

Quoting all Posts in this Thread to be able to follow it a bit as it sounds a bit interesting, from @iimfun's Reply, but I guess it's not directly solved from the several Replies from @OP, that seems to belong to the in total 3 Users I've foed since I joined the Forum about 4 years ago (and started to help other Users...), but anyway I quote all Posts because I don't see them otherwise...

And hum, @OP mentioning their FCI directly (is nearly too perfect...!) , I guess my "pain-in-the-ass/foe" Thing probably comes from me asking @OP to mention their FCI at some time, and I guess it went awrok..., oops...!
footyfacts wrote:

Code: Select all

Firefox  52.2.1 (32-bit)
Imacros VERSION BUILD=9030808 
Windows XPsp2
They changed the page on me and XPATH is a bit obtuse for an old man like me
I now get the product code and product price extract twice

My code (courtesy of others who have helped previously)

Code: Select all

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]" Extract=Txt                 <== This ends up with  553919553919 
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]" Extract=Txt                  <== this ends up with $98.60$98.60
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt
SAVEAS TYPE=EXTRACT FOLDER=F:\PC-Stuff\Sendmail\DanPages FILE=ALM_EXT.CSV
SAMPLE TR DATA

Code: Select all

<tr bgcolor='#ECECFF'>
  <td><a href="javascript:launchWindow('History?ProductId=553919');"  title="CRWN SEAL 750ML" class="phtip">553919</a> <input type="hidden"
                    name="ProductId" value="553919"/></td>
  <td>CRWN SEAL MOSC 750ML</td>
  <td align="center">6</td>
  <td align="center">6</td>
  <td align="right">$ 98.60<input type="hidden" name="UniversalDealIncGST" value="0.00" /></td>
  <td align="center"><a   title="No Current Allowance" class="alwtip">$ 0</a></td>
  <td align="center"><font face="courier new" size="3"><tt><b> </b></tt></font><input type="text" name="OrderCtnQty" value=""
        class="formfield" onfocus="resetKeepAliveTime();" maxlength="3" size="5"/></td>
  <td align="center"><input type="hidden" name="OrderUnitQty" value=""/> </td>
   <td><a href="javascript:launchWindow('/alm/user/LineCalculator?ProductId=553919&PackQty=6&WetRate=29.0&
          BaseCostPriceExGST=69.49','popup',600,400);"  title="View Line Calculator" class="tip"><img src="media/images/icons/inner_calculator.gif" 
          align="absmiddle" border="0" hspace="1" null></a>                  <input type="hidden" name="UnitPriceExGST" value="98.60"/></td>
   <td align="center"><INPUT type="hidden" name="IsAddProduct" value="false"><input type="checkbox" name="IsAddProduct"/></td>
</tr>
iimfun wrote:Maybe the input elements cause troubles. What about this way?

Code: Select all

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
or

Code: Select all

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/input" Extract=Txt
and

Code: Select all

Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/input" Extract=Txt
If it doesn't work then you should use the EVAL command.
footyfacts wrote:My solution isn't elegant however the following does solve my problem
although it is probably going to break when they change things on me again
I do have the "safety" in knowing that change is not often because it is
not an e-commerce site it is just the wholesaler/retailer ordering

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
set !LOOP 1
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[1]/a" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[2]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[3]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[4]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/b[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[5]/nobr[1]" Extract=Txt
Tag XPath="//Tr[@bgcolor='#ECECFF'][{{!Loop}}]/Td[6]" Extract=Txt
I would still like to know however why the NOBR fails when there is a <b><nobr> tag pair
surely the test is irrelevant to the precedence of the tags and indeed why the original
extracts the $$ amount twice (I know why the 1st tag did as it is there twice)

gregF
Arrgghh, but nope...,!, I thought it was the perfect try-and-fall/fail Thread to learn 'XPATH', but nope...!: URL not mentioned..., pity...!! :roll:
But it looks a bit like the 'EVENT' Mode and if selecting/locating Cells in an HTML Table, Relative Positioning would do the same job and is much easier to use, I would think... :?

Maybe one day @OP will find the ']CODE[' Meta-Tags...!? :wink:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
footyfacts
Posts: 11
Joined: Tue Jul 02, 2013 11:48 am

Re: XPATH QUERY

Post by footyfacts » Mon Sep 04, 2017 3:19 am

Pesky MetaTags ''

URL was not useful to problem and not posted as you have to login to the secure site
which is why I posted HTML snippets of data

Personally I think the final Code snippets for XPath are now quite useful for a Tyro
and could set many a beginner on their way

I am too cranky nowadays to bother having another comp language/markup in my brain
beyond the 200/300 in there now after 38 years of coding

GregF
Post Reply