MS Having Trouble waiting for a Dynamically Generated Web Page to Load...

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

MS Having Trouble waiting for a Dynamically Generated Web Page to Load...

Post by rjw524 » Mon Jun 12, 2023 10:33 pm

Hi,

I don't really have code for this but most of my macros center around my work and interfacing with the CRM my company uses (Salesforce).

Most of that work includes opening customer or prospect profiles by clicking on their name and then scraping or viewing some data in the profile and closing it.

When I click on these profile names the actual profile opens in a new page.

The problem is because these pages are dynamically generated and take various times to load and I can't tell MS the "exact" page to wait open because it could have a different name each time depending on the name.

This causes the macro to either stop entirely or perform the next command too soon because it really can't tell if the page is completely loaded or not.

I've tried Timeouts, waiting for specific images to load, etc. Nothing works.

Does anyone know how to address this?

Thanks!

RJ

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: MS Having Trouble waiting for a Dynamically Generated Web Page to Load...

Post by Dorian (MJT support) » Tue Jun 13, 2023 9:05 am

If you're not using the Chrome/Edge functions, then maybe this is something you should investigate - although I seem to remember you're not able to do this. If you can't then maybe looking for a particular pixel colour might be a visual clue to whether an element has loaded?

If you are using Macro Scheduler's Chrome/Edge funtions they should wait until they deem a page to finish loading. However, it's possible that some page elements may still be loading. I've experienced that too.

If so, you can create a loop which keeps checking to see if an element is found. The WriteLn is in there for demonstration purposes... writing a 0 while it isn't found, and a 1 (or greater) when it is. :

Code: Select all

ChromeFindElements>session_id,id,TestElement,elements
let>loadtest=elements_count
writeln>d:\sizecheck.txt,,loadtest
while>loadtest=0
  ChromeFindElements>session_id,id,idstartDate2,elements
  let>loadtest=elements_count
  writeln>d:\sizecheck.txt,,loadtest
endwhile
Also note that if your page is loading in a new tab, you'll need to use Chrome/EdgeSwitchWindow (link).

So the link click, switchwindow, and wait for element to load would resemble this :

Code: Select all

Let>CHROMEDRIVER_EXE=c:\chromedriver.exe
Let>TheURL=https://somewhere.com/this.htm
ChromeStart>session_id

ChromeNavigate>session_id,url,%TheURL%

//Find and click on a hyperlink (which opens a new tab)
ChromeFindElements>session_id,link text,MyLink,elements
ChromeElementAction>session_id,elements_1,click

//Switch windows
ChromeGetWindows>session_id,window_list
ChromeSwitchWindow>session_id,window_list_2,result

//Element load loop
ChromeFindElements>session_id,id,TestElement,elements
let>loadtest=elements_count
writeln>d:\sizecheck.txt,,loadtest
while>loadtest=0
  ChromeFindElements>session_id,id,idstartDate2,elements
  let>loadtest=elements_count
  writeln>d:\sizecheck.txt,,loadtest
endwhile
Yes, we have a Custom Scripting Service. Message me or go here

rjw524
Pro Scripter
Posts: 104
Joined: Wed May 09, 2012 9:45 pm
Location: Michigan

Re: MS Having Trouble waiting for a Dynamically Generated Web Page to Load...

Post by rjw524 » Tue Jun 13, 2023 7:40 pm

I'm going to try the pixel color and see if that works. Thanks!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts