Jump to content
Macro Express Forums

wait for firefox window to load and run macro

Recommended Posts

Respected friends,


i need help in a small issue.


scenario is:


i run a micro in firefox which perfom function on one page
and then go to the next page..

.some times page take a lot of time to open due to poor internet speed.

so macro over run....

what i required is:

1. the micro do the job on first page
2. then go to the next page:
3. wait for the next page to load
4. then perform required function on the next page as desire.



Link to comment
Share on other sites

This is one thing that MEP does not handle well. I have written many macros that have had this same problem and it's not easy to solve. You should first search this forum and read some of the solutions provided before. But I'll tell you now that the common approaches are to use the browser's automation facilities or to pixel scan the status bar for text or the green progress indicator until complete. I'm not sure which automation features FF has, each has different built in or add-on utilities.


I struggled with this for years until I finally gave up and started writing programs for my clients in .NET using HTTP request/response where there are no timing issues like you're dealing with now. If you would like to hire someone to do this for you contact me in a PM and we can discuss. I give a free hour of consultation for prospective clients.


Search the forum you will find some sample macros for the techniques I have described and much more. Then come back to this thread with your questions and we can help you from there.

Link to comment
Share on other sites

Here is a simple loop that waits up to 30 seconds for a page to load, based on knowing that a yellow icon will appear when the page has loaded. As soon as the color appears the macro exits from the loop and does whatever else has to be done. This might or might not work for you depending on the page. For example, if the yellow icon appears but the page has only partially loaded, the macro's subsequent actions might fail.


Mouse Move Screen 519, 553
Repeat Start (Repeat 3000 times)
Get Pixel: Under Mouse into %N1%
If Variable %N1% = 52479
Repeat Exit
End If
Delay 100 Milliseconds
Repeat End

Link to comment
Share on other sites

I have used rberq's approach, as well as the similar technique of monitoring the shape of the mouse cursor.


But as Cory notes, there is no elegant solution using Macro Express.


Nevertheless, kludges (like pixel sniffing or mouse cursor monitoring) can be made to work reliably. I use them all the time. But these "solutions" take time to massage toward reliability.


Note: if you check pixels, the colours may change when you update Firefox, so plan accordingly! E.g.:


Get Pixel Color from Beneath the Mouse into %PixelColour% // Target colour

If Variable %PixelColour% Equals "12345" // Look for "12345" in Firefox 46. Target was "12333" prior to Firefox 41.
// Do something
End If

Link to comment
Share on other sites

  • 3 weeks later...

I'm late to the thread but if you're still around I echo what Alan, Bob and Cory said about it being tricky to get working. And a surprising long term flaw in MX Pro's powerful repertoire of commands. My own approach is to use the FF add-on called Throbber Restored. My macro detects when it stops throbbing/spinning.

// Revised Saturday 6 February 2016, 1506
// Assumes FF is active. (Activate Window and Wait for Window Title don't seem to work.)
//  Black dots,Throbber Restored add-on, 2014.
// First ensures FF is at 0,0
// FF layout critical. Watch for changes in design/position of throbber.
Window Reposition:  - Mozilla Firefox Position: 0, 0
Delay: 500 milliseconds // To allow spinning to start.
// Gets colour at a single position (at the 'west ' section of the throbber) at 6 shortly spaced intervals and then tests if the are ALL back to the static colour.
Variable Set Integer %nDelay% to 80
Repeat Until %N[99]% Does not Equal "%N[99]%"
  Get Pixel Color at (42, 60) Relative to Screen into %PixCol1%
  Delay: %nDelay% milliseconds // mS
  Get Pixel Color at (42, 60) Relative to Screen into %PixCol2%
  Delay: %nDelay% milliseconds // mS
  Get Pixel Color at (42, 60) Relative to Screen into %PixCol3%
  Delay: %nDelay% milliseconds // mS
  Get Pixel Color at (42, 60) Relative to Screen into %PixCol4%
  Delay: %nDelay% milliseconds // mS
  Get Pixel Color at (42, 60) Relative to Screen into %PixCol5%
  Delay: %nDelay% milliseconds // mS
  Get Pixel Color at (42, 60) Relative to Screen into %PixCol6%
  Text Box Display: 
  If Variable %PixCol1% Equals "12106170"
  If Variable %PixCol2% Equals "12106170"
  If Variable %PixCol3% Equals "12106170"
  If Variable %PixCol4% Equals "12106170"
  If Variable %PixCol5% Equals "12106170"
  If Variable %PixCol6% Equals "12106170"
  // Then web site is ready.
    Repeat Exit
    Delay: 50 milliseconds
  End If
End Repeat

Link to comment
Share on other sites

The Macro Express command that detects when an Internet Explorer page is fully loaded does not work reliably either, or at least that's been my experience.


So whether I am writing a macro for IE or Firefox, I usually end up using kludges to detect loaded webpages.


Here are a few rules for these kinds of kludges:


1. Avoid this kind of loop:


Repeat Until %PixelColour% Equals "12345"

If the pixel colour is not found, the macro is looping forever. Instead, repeat a finite number of times, and then declare failure!


Repeat Start (Repeat 100 times)
Get Pixel Color from Beneath the Mouse into %Pixel%
If Variable %Pixel% Equals "12345"
// Perform next step after pixel is found
Macro Stop
End If
Delay: 1 seconds
End Repeat
Text Box Display: Pixel colour 12345 was not found!


2. Don't use a timed delay when you can use a "regular delay:


Delay: 1000 milliseconds, without ability to halt


Instead, use this delay:

Delay: 1000 milliseconds


In macros with a lot of looping, the former tends to freeze Macro Express more often than the latter.


Anything else?

Link to comment
Share on other sites

In defense of MEP active web stuff is difficult. .NET has a WebBrowser control that is the engine for Internet Explorer. I think that's why there's no automation facilities for IE. They figure they gave you the engine so you can simply build your own automated browser if you want. Many new scrapers try to use it and it too is difficult to manage timing and what not. And mostly it's the result of bad web developers. And even if you get the thing's timing working it's slow. And when you get the HTML document it's often a problem to extract things from it using the DOM (Document Object Model). IE HTML is a structure of elements so one should be able to directly work with these elements. But often the code doesn't adhere to standards, is poorly written, or is flat wrong. There's an entire other third party class out there just to 'fix' that.


What I eventually settled on was to use the HTTPRequest/Response classes directly. This way I get the actual text of the document and it's not rendered anywhere. It's just a big string variable. This way my program is issuing and processing it's own requests and responses and all these issues go away. And it's very fast as it doesn't download graphics, render, or execute script. But it's more technical and takes a while to get the hang of creating and executing your own requests. I know do hundreds of thousands of pages a day this way and it works very well.


Anyway my point is that one shouldn't be too quick to condemn MEP's shortcomings. Web automation is a lot more difficult than it seems.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...