IE - Restart if element isn't found?

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
BLiTzKrIeGx1337
Posts: 41
Joined: Sat Nov 16, 2019 10:05 pm

IE - Restart if element isn't found?

Post by BLiTzKrIeGx1337 » Fri Aug 13, 2021 5:39 pm

iMacros 12.6.505.4525
Win10x64
IE11


Part of one of the macros I run in IE searches for an item and selects it by the item's name, lately though, it has occasionally been unable to find the element and errors out despite the item existing, it looks like sometimes, for some reason, the search box gets cleared before imacros tags the search button causing it to return no results, I've messed around a bit adding various waits and refreshes in different ways but I still keep getting the same issue, is there a way I can add in a script that would restart the macro at its current loop?

Code: Select all

URL GOTO=https://heraldpg.myprintdesk.net/DSF/Admin/ManageProducts.aspx?forcedToLoadOldClassic=true
SET !DATASOURCE C:\Users\forms\Desktop\AFDmacroCSVs\image&content.csv
SET !LOOP 48
SET !DATASOURCE_LINE {{!LOOP}}
SET !TIMEOUT_STEP 100
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:ctl00$ctl00$C$M$TextBoxSearch CONTENT={{!COL1}}
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:IMAGE ATTR=NAME:ctl00$ctl00$C$M$ButtonSearch
WAIT SECONDS=3
TAG POS=1 TYPE=A ATTR=TXT:{{!COL1}}

^If the tag above isn't found, start the current loop over again

TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:ctl00$ctl00$C$M$ctl00$W$ctl01$_BigIconByItself$EditProductImage
TAG POS=3 TYPE=INPUT:RADIO ATTR=NAME:ctl00$ctl00$C$M$ctl00$W$ctl01$_BigIconByItself$ProductIcon$CHOICE
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=NAME:ctl00$ctl00$C$M$ctl00$W$ctl01$_BigIconByItself$ProductIcon$ChkUseSameImageIcon CONTENT=YES
Thanks in advance!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: IE - Restart if element isn't found?

Post by chivracq » Fri Aug 13, 2021 8:55 pm

BLiTzKrIeGx1337 wrote:
Fri Aug 13, 2021 5:39 pm
iMacros 12.6.505.4525
Win10x64
IE11


Part of one of the macros I run in IE searches for an item and selects it by the item's name, lately though, it has occasionally been unable to find the element and errors out despite the item existing, it looks like sometimes, for some reason, the search box gets cleared before imacros tags the search button causing it to return no results, I've messed around a bit adding various waits and refreshes in different ways but I still keep getting the same issue, is there a way I can add in a script that would restart the macro at its current loop?

Code: Select all

URL GOTO=https://heraldpg.myprintdesk.net/DSF/Admin/ManageProducts.aspx?forcedToLoadOldClassic=true
SET !DATASOURCE C:\Users\forms\Desktop\AFDmacroCSVs\image&content.csv
SET !LOOP 48
SET !DATASOURCE_LINE {{!LOOP}}
SET !TIMEOUT_STEP 100
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:ctl00$ctl00$C$M$TextBoxSearch CONTENT={{!COL1}}
WAIT SECONDS=1
TAG POS=1 TYPE=INPUT:IMAGE ATTR=NAME:ctl00$ctl00$C$M$ButtonSearch
WAIT SECONDS=3
TAG POS=1 TYPE=A ATTR=TXT:{{!COL1}}

^If the tag above isn't found, start the current loop over again

TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:ctl00$ctl00$C$M$ctl00$W$ctl01$_BigIconByItself$EditProductImage
TAG POS=3 TYPE=INPUT:RADIO ATTR=NAME:ctl00$ctl00$C$M$ctl00$W$ctl01$_BigIconByItself$ProductIcon$CHOICE
TAG POS=1 TYPE=INPUT:CHECKBOX ATTR=NAME:ctl00$ctl00$C$M$ctl00$W$ctl01$_BigIconByItself$ProductIcon$ChkUseSameImageIcon CONTENT=YES
Thanks in advance!

"is there a way I can add in a script that would restart the macro at its current loop?"
=> Yep, your different 'WAIT' Statements won't help as you already have a long '!TIMEOUT_STEP' (= 100 Sec), so if some Element(s) do(es)n't get found, an extra [1-3] Sec won't change that...

Then..., yep-yep, that's possible... 2 different Techniques and 2 different Mechanisms...:

For both you will first need to extract that Link before "really" clicking on it to check if it exists...
Then using 'EVAL()', you will make "a lot of Things" conditional, ah-ah...! :P 8) :twisted:

But hum, first let me ask a Qt...: Do the 3 'TAG' Statements after the "TAG POS=1 TYPE=A ATTR=TXT:{{!COL1}}" need to be disabled/muted or won't they do anything if the Link was not found/not clicked...?
If that's the Case, then simply using '!ERRORIGNORE' + shortening '!TIMEOUT_STEP' will "do the Trick"...
Otherwise you'll need to compute the 'POS' Value (to enable/disable those Statements), or to conditionally switch to a 2nd Tab (already open, or that could conditionally be opened) where those 3 Statements won't do anything...

Then for the Loop Counter, you will need a Mechanism to "keep track" of the Nb of Faults to adjust the Counter for the '!DATASOURCE_LINE' Value, either using the OS Clipboard (with the '!CLIPBOARD' Var), or using some Temp mini-'.txt' or '.csv' File which are the 2 "main" Ways for iMacros to "communicate" with itself between 2 Loops. :idea:

>

Mini-Difficulty you might encounter, there is a Bug with the 'ADD' Command when using Negative Values when the Value = 0, then iMacros will append a "-0" as a String to the original Value... => "48-0" will remain "48-0" (as a String), instead of giving simply "48" as Result (as a Number).
=> Workaround is to use 'EVAL()' again also...

Oh yeah, another "mini-Difficulty" is the 'FILEDELETE' Command that you'll need, this Command has "a Life of its own", ah-ah...! The File needs to exist, or you need '!ERRORIGNORE'. Make sure to allow for about 0.5 Sec between Read/Delete/Recreate it. In "some" Versions, it is (by Design) disabled on the 'DataSources' Default Folder, but I think you should be "safe" with your "C:\Users\forms\Desktop\AFDmacroCSVs\" Folder, or it might even only work on the Default (iMacros) 'Downloads' Folder. (I don't know how it behaves in your v12.6 for IE Version.)

>

It's not very complicated to implement, I find the mini-Temp File more "reliable" than using the OS Clipboard, as if you are running your Script "in the Background" and go doing "other Things" on your Computer, if you "forget" about the Script and start using the OS Clipboard, you will screw the Script and the Looping... But that's your "Call"... :wink:

Then a '.txt' File is more "flexible" than a '.csv' File, and if you need to disable/mute the last 3 Statements in your Script, that '.txt' File could be used to be opened in the 'TAB_2' and serve as Report/Log about the "Progress" of the Script. And a '.txt' File can be opened in a Browser + in 'Notepad' for example, and iMacros can still delete/write/save it, the File is not "Locked" at the OS Level. 8)
- (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...
BLiTzKrIeGx1337
Posts: 41
Joined: Sat Nov 16, 2019 10:05 pm

Re: IE - Restart if element isn't found?

Post by BLiTzKrIeGx1337 » Fri Aug 13, 2021 10:55 pm

For both you will first need to extract that Link before "really" clicking on it to check if it exists...
Then using 'EVAL()', you will make "a lot of Things" conditional, ah-ah...! :P 8) :twisted:

But hum, first let me ask a Qt...: Do the 3 'TAG' Statements after the "TAG POS=1 TYPE=A ATTR=TXT:{{!COL1}}" need to be disabled/muted or won't they do anything if the Link was not found/not clicked...?
If that's the Case, then simply using '!ERRORIGNORE' + shortening '!TIMEOUT_STEP' will "do the Trick"...
Otherwise you'll need to compute the 'POS' Value (to enable/disable those Statements), or to conditionally switch to a 2nd Tab (already open, or that could conditionally be opened) where those 3 Statements won't do anything...
Yeah that's the big issue here, no loop in the csv can be skipped or it will cause issues.

I'm a bit confused, what do you mean by "compute the 'POS' value?" I'm not familiar with that. It looks like your thinking is to try to get around the loop (???) -
Then for the Loop Counter, you will need a Mechanism to "keep track" of the Nb of Faults to adjust the Counter for the '!DATASOURCE_LINE' Value, either using the OS Clipboard (with the '!CLIPBOARD' Var), or using some Temp mini-'.txt' or '.csv' File which are the 2 "main" Ways for iMacros to "communicate" with itself between 2 Loops. :idea:
and then pull the failed loop numbers from the clipboard or txt file to retry them, is that correct?
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: IE - Restart if element isn't found?

Post by chivracq » Sat Aug 14, 2021 1:19 pm

BLiTzKrIeGx1337 wrote:
Fri Aug 13, 2021 10:55 pm
Yeah that's the big issue here, no loop in the csv can be skipped or it will cause issues.

Yeah-yeah, of course, I understood that, and the Implementation(s) I suggested would take care of that, of course...!

>>>
BLiTzKrIeGx1337 wrote:
Fri Aug 13, 2021 10:55 pm
I'm a bit confused, what do you mean by "compute the 'POS' value?" I'm not familiar with that. It looks like your thinking is to try to get around the loop (???) -

Hum, OK, but you didn't understand the "Logic" at the Level "above" that Part because/and you didn't answer the Qt I asked...
The "compute the 'POS' Value" (or "switch to 'TAB_2'") Parts are only needed depending on your Answer to the following Qt again:

:arrow: Do the 3 'TAG' Statements after the "TAG POS=1 TYPE=A ATTR=TXT:{{!COL1}}" need to be disabled/muted or won't they do anything if the Link was not found/not clicked...? :?: :?: :?:

>>>
BLiTzKrIeGx1337 wrote:
Fri Aug 13, 2021 10:55 pm
Then for the Loop Counter, you will need a Mechanism to "keep track" of the Nb of Faults to adjust the Counter for the '!DATASOURCE_LINE' Value, either using the OS Clipboard (with the '!CLIPBOARD' Var), or using some Temp mini-'.txt' or '.csv' File which are the 2 "main" Ways for iMacros to "communicate" with itself between 2 Loops. :idea:
and then pull the failed loop numbers from the clipboard or txt file to retry them, is that correct?

Euh, nope, not exactly what I meant, what I meant is "pull the Number of failed Loops", => only keep track of "How Many", and we use that Nb to "adjust" the 'Loop_Nb' to use for '!DATASOURCE_LINE' as the "raw" '!LOOP' Value will get "desynchronized" at some point...
So for example, if you are at '!LOOP'=53, and you already had 2 "Failed Loops", => need to use "51" for '!DATASOURCE_LINE'. :idea:

>>>

And hum, another possible Implementation, would be, still using Clipboard or Temp '.txt' File (but again, using a Temp '.txt' File is much more "reliable" than the OS Clipboard), to simply keep track of the "last" successful Row_Nb in the DataSource, and for each Loop, simply need to add 1 to use for '!DATASOURCE_LINE'. And you don't care anymore about the Value for '!LOOP'.

But you'll need to add a Mechanism to "reset" (or not!) that "last successful Row_Nb" for each time you run the Script "again", if you run it a few minutes after the previous Run and want it to go further with the Processing, or if you run it the next day, and want it to start again from Row_1...
And that's a little bit more "complicated" than it first looks...
- (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...
BLiTzKrIeGx1337
Posts: 41
Joined: Sat Nov 16, 2019 10:05 pm

Re: IE - Restart if element isn't found?

Post by BLiTzKrIeGx1337 » Sat Aug 14, 2021 3:29 pm

chivracq wrote:
Sat Aug 14, 2021 1:19 pm
:arrow: Do the 3 'TAG' Statements after the "TAG POS=1 TYPE=A ATTR=TXT:{{!COL1}}" need to be disabled/muted or won't they do anything if the Link was not found/not clicked...? :?: :?: :?:
They won't do anything if the link isn't clicked, the link takes you to a different page where those TAGs exist. So your earlier solution for shortening the !TIMEOUT_STEP and !ERRORIGNORE would work to get through the loop.

Code: Select all

URL GOTO=https://heraldpg.myprintdesk.net/DSF/Admin/ManageProducts.aspx?forcedToLoadOldClassic=true
SET !DATASOURCE C:\Users\forms\Desktop\AFDmacroCSVs\image&content.csv
SET !LOOP 48
SET !DATASOURCE_LINE {{!LOOP}}
SET !TIMEOUT_STEP 100
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:ctl00$ctl00$C$M$TextBoxSearch CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:IMAGE ATTR=NAME:ctl00$ctl00$C$M$ButtonSearch

SET Timeout_Cond EVAL("var s='{{!COL1}}'; var z; if(s!='#EANF#'){z=0;} else{z=100;}; z;")
SET !TIMEOUT_STEP {{Timeout_Cond}}

TAG POS=1 TYPE=A ATTR=TXT:{{!COL1}}
I believe this would work for deciding whether or not to skip the loop.

Code: Select all

TAB OPEN
TAB T=2
URL GOTO=data:text/html, <html contenteditable>
Rather than having to worry about the clipboard or keeping a .txt file around, but I did some searching and I'm not sure how to record # of failures?

I won't be able to test for a few days as everything is on my work computer and I'm on vacation. Thanks!
Post Reply