Mark
Mark

Reputation: 37

AutoIt wait for Chrome to load

Using AutoIt, how can I determine when a chrome browser has finished loading? Any working examples are highly appreciated. I read there was a way with checking pixel colors, but that doesn't seem very efficacious.

Upvotes: 0

Views: 2804

Answers (1)

Anson W Han
Anson W Han

Reputation: 409

If you are opening Chrome using AutoIt and immediately navigating to a specific web page everytime, then one option is to run a loop checking for particular content on the page (such as copyright text in the footer).

A rough skeleton of the code might be:

Opt('WinTitleMatchMode', 2) ;ensure partial window title matches on and WinActivate, WinExists, WinWait, WinWaitActive, WinKill commands

; code to load chrome via Run dialog goes here
WinWaitActive("Chrome")
sleep(500)
send("^a") ;select all on the browser's active tab
sleep(250)
send("^c") ;copy it into the clipboard
sleep(250)
Local $webPageContents = ClipGet()
; if statement or while loop to check for the existence of some string of content on the webpage

Unfortunately, this won't actually determine if the page has returned with an http 200 status response and all assets/images are fully loaded, but might suffice.


If you absolutely need to know that the page has fully loaded, you'd probably want to script opening the Web Inspector/Dev Tools and navigating to the Network panel, reading the Network Requests data repeatedly every couple seconds for until the previous state and current state match to determine the page has finished loading all its assets.

enter image description here

Upvotes: 1

Related Questions