Refresh a page until an item is shown

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
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Refresh a page until an item is shown

Post by chivracq » Sun Nov 21, 2021 9:39 pm

LuisOjeda wrote:
Sun Nov 21, 2021 9:05 pm
Windows 10, version 21H2 (Spanish)
Chrome 96.0.4664.45 (64 bit)
iMacros for Chrome, Personal Edition


¡Good evening, everyone!

First of all, I would like to apologise in advance if I use the incorrect terminology. I am very new to iMacros and I am still learning.

I have been reading several posts and trying different methods, but unfortunately I don't manage to write the macro that I want.

My goal: I want to refresh a page until a link appears. Once the link appears, I want to click on it and then click on another button ("Accept") that appears on a second page. I have deleted sensitive information, since I can't publish it online. So far, the macro that I have created is the following one:

Code: Select all

VERSION BUILD=1011 RECORDER=CR
WAIT SECONDS=0
SET !TIMEOUT_STEP 0 
SET !ERRORIGNORE YES 
URL GOTO=https://name-of-the-website.
REFRESH
WAIT SECONDS=0.3
TAG POS=1 TYPE=DIV ATTR=TXT:Click<SP>Here
WAIT SECONDS=0.3
TAG POS=1 TYPE=BUTTON ATTR=TXT:Accept
1. I have included "WAIT SECONDS" after the clicks to allow some time for the page to reload. Not sure, however, if I really need it. Maybe iMacros waits until the website is loaded and moves to the next step (that would save me 0.6 seconds).

2. At the moment, iMacros works but runs the entire script, even when the button with the text "Click Here" doesn't appear.

3. I would like to know if there is any way in which iMacros refreshes the website until the button "Click Here" appears and then follows the rest of the script.

Thank you in advance for any help you can provide. I apologise once again if I have used the wrong terminology or if I didn't express myself correctly.

Have a great evening!

=> FCI:

Code: Select all

iMacros v10.1.1 for CR, 'PE', CR96_x64, Win10_x64 v21H2 (SP).
(The iMacros for CR Version was missing, but is visible from your Script...)

Then, well, your Script looks just fine to me, this is "the Way" to use iMacros indeed... :D
... Except for the `URL GOTO` + `REFRESH` Commands next to each other, they both do the same Action, so this is "Double" and you are loading the Page twice before the Script will start looking for the "Click Here" 'DIV' (or Link), => only keep the `URL GOTO` Command I would say, it is more "reliable" than `REFRESH`... :idea:

If you further want to "tune" your Script for Speed, you can indeed try shortening the x2 `WAIT` Statements, + also shortening the `!TIMEOUT_PAGE` Setting (Default = 60 Sec currently), with the "Risk" that "sometimes" maybe, the Page will not load correctly/completely, but it depends on the Site and on your Internet Connection/Speed to find the "right Balance" between Reliability and Speed... :idea:

What also helps to load a Page/Site as quick as possible, => is to use some Ad-Blocker Extension and to try to block any "external"/2nd or 3rd Party Scripts like 'FB'/'Instagram'/'LinkedIn'/'Google Adsense'/etc... Plugins on the Page, or even Images, ... without "breaking" some Functionality from the Site... :P
- (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...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Refresh a page until an item is shown

Post by chivracq » Tue Nov 23, 2021 3:36 am

LuisOjeda wrote:
Mon Nov 22, 2021 7:17 am
¡Good morning, chivracq!

Thank you very much for your reply.

I have followed your advise. However, I noticed that if I only used the command "Go to", the website doesn't refresh if it is already open. So I have used the command "Refresh" on it's own, without the "Go to" to avoid any duplication.

I have also reduced the amount of time of the "Wait" commands :) ¡Thank you for the tip!

My script looks like this now:

Code: Select all

VERSION BUILD=1011 RECORDER=CR
WAIT SECONDS=0
SET !TIMEOUT_STEP 0 
SET !ERRORIGNORE YES 
REFRESH
WAIT SECONDS=0.1
TAG POS=1 TYPE=DIV ATTR=TXT:Click<SP>Here
WAIT SECONDS=0.1
TAG POS=1 TYPE=BUTTON ATTR=TXT:Accept
The only question that I have is the following: is there any possibility of skipping the last three steps if the button "Click Here" doesn't appear? I would like that the website just refreshes and once the button appears, then the macro would click on it and then on the next button "Accept".

Thank you once again for all your help!

Have a great day ahead!

Yeah, "morning"/"evening" don't really mean "much" on a TechForum with Users "all over the World", all living in different Time-Zones, ah-ah...! :idea:

>>>
"I noticed that if I only used the command "Go to", the website doesn't refresh if it is already open. So I have used the command "Refresh" on it's own, without the "Go to" to avoid any duplication."
=> Hum, OK, like I said earlier, both Command do the same Action, so I'm a bit "surprised" by your Post... :o :?
You could be right, but I would need to "investigate" by myself, but you didn't (want to) post the URL of the Page/Site, then I can't say no more...

>>>
"The only question that I have is the following: is there any possibility of skipping the last three steps if the button "Click Here" doesn't appear? I would like that the website just refreshes and once the button appears, then the macro would click on it and then on the next button "Accept"."
=> Well it's not 3 (Steps/Lines) but 2, iMacros "needs a way" to check if some HTML Element is present or not, so the 'TAG' Statement on the 'DIV' Element is "that way"...

Every Step in an iMacros Script takes about [5-7-10] ms (Milli-Seconds) [=> 1000 ms = 1 s], your "WAIT SECONDS=0.1" already "consumes" 100 ms (OK, maybe 105-107-110 ms actually, I'll use "110 ms" for further Calculations), and the next 'TAG' Statement trying to click on the 'Accept' Button only [5-7-10] ms again... Why do you care...?
If you really care about those [5-7-10] ms, then shorten your 'WAIT' Statement to "0.09", then you are already on the "safe Side"...

The Recommendation(s) I gave you about `URL GOTO` + `REFRESH` are about [1-5] FULL Seconds..., about `WAIT` Statements, => well Diff between "=0.3" and "=0.1" is still 200 ms, while iMacros Statements take about 10 ms to be executed (with `!TIMEOUT_STEP`=0 of course), => do you "see" the Difference(s) between 5000 >> 200 >> 10 ms...?

Your current Implementation with `TAG` + `WAIT` + `TAG` is 10+110+10=130 ms.

Would you want to check if the first `TAG` exists, then it would give:
`TAG` + `EXTRACT~ (= 30 ms) + `EVAL()` (= 50 ms) + `WAIT (=110 ms) + `TAG` (= 10 ms), => Total = 30+50+110+10=200 ms, => 70 ms "slower" than your current Script..., although, it would be possible with a 2nd `EVAL()` to conditionally compute the `WAIT` Value to "0.0" instead of "0.1", => allowing you to save 20 ms in total instead of the "70 ms" I just mentioned... (`WAIT` goes from 110 ms => 10 ms, but + `EVAL()` => + 50 ms. => -50 ms in total.)

And this all "Calculation" is again all completely in the Milli-Seconds..., more-more-more important and time consuming (again, also in the Seconds..., => 1000 ms / 2000 ms / 3000 ms...!) about what I had earlier mentioned about External/2nd_3rd Party Scripts, => why do you care about 10 ms, or even 30 ms or 70 ms, but not about 3000 ms (= 3 sec...!)...!? :?

And "maybe" I'm exaggerating a little bit with 5000 ms for Page Loading and 3000 ms for External Scripts, depending on the Sites, I've seen Sites/Pages loading in about 1 sec in total, with the whole Page + all External Scripts..., but we are still taking about 1 iMacros Step in a Script still being 100 or 50 times quicker than a Page or Script loading... :idea:
- (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...
Post Reply