Help with automation Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
stridd

Help with automation  Topic is solved

21 Sep 2017, 13:28

Is it possible to make a script to recognize if a web page is loaded?

I made a script (with help from here) to automate the uploading of files to a site. After every file uploaded, it sends me to this exact page that never changes, let's call this page "Success". I've set a Sleep that I feel is enough for Success to load, then it clicks a button to go back to the uploading page, looping this process until all the files are uploaded. My issue is that sometimes Success takes more than I had set, screwing it all over. I could set a even more longer Sleep time, but generally it takes only a split second to load it, but sometimes it doesn't.

Can someone guide me to what I should look into?

Code: Select all

Global MyCounterVar := 14084
Loop, 825

{
	MyCounterVar+=1
	Tooltip % MyCounterVar
	Sleep 81
	
	SendInput {Raw}2015
	SendInput {Tab}
	SendInput {Raw}%MyCounterVar%
	SendInput {Tab}
	SendInput {Raw}File n. %MyCounterVar%
	SendInput {Tab}
	SendInput {Raw}%MyCounterVar%
	Sleep, 20000
	SendInput {Tab}
	SendInput {Enter}
Continue
}

return ;
#x::Pause
#c::Reload
Esc::ExitApp
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Help with automation

21 Sep 2017, 17:05

Hi,

If it sends you to a new page this page has probably not the same title as the first one so that you can probably take advantage of the WinWait command. Below a simple example using chrome: once the Gmail link is clicked from www.google.fr and the browser navigates @ https://accounts.google.com/... the MsgBox appears.

Code: Select all

run, chrome.exe www.google.fr
WinWait, Gmail - Google Chrome
MsgBox, success
my scripts
strid
Posts: 1
Joined: 21 Sep 2017, 10:31

Re: Help with automation

21 Sep 2017, 17:40

Hi A_AhkUser, both pages have the same title but not the same url (obviously).

It will show this message though, could I use it somehow?

Code: Select all

<p class="display">File uploaded successful.</p>
This is the whole script, I omitted some parts in the OP.

Code: Select all

Global MyCounterVar := 14084
Loop, 825

{
	MyCounterVar+=1
	Tooltip % MyCounterVar
	Sleep 81
	
	SendInput {Raw}2015
	SendInput {Tab}
	SendInput {Raw}%MyCounterVar%
	SendInput {Tab}
	SendInput {Raw}File n. %MyCounterVar%
	SendInput {Tab}
	SendInput {Enter}
	SendInput {Raw}%MyCounterVar%
	SendInput {Enter}
	SendInput {Tab}
	SendInput {Enter} ;this is the part where it upload the file, then load "Success"
	Sleep, 20000 ;20 seconds wait to "guarantee" that Success will load
	MouseMove, 1258, 260
	Click ;send me back to the uploading page
Continue
}

return ;
#x::Pause
#c::Reload
Esc::ExitApp
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Help with automation

22 Sep 2017, 09:01

Hi,

You can use WinWaitClose (i.e. "WinaitNotExist") instead: altougth the title is nearly instantaneous updated when the page loads, it remains empty for a few miliseconds and will force WinWaitClose command to time out (note: change tab will produce the same effect since it updates the browser main title too).

Code: Select all

run, chrome.exe --app=http://www.google.fr/
WinWait, Google
sleep, 2000
sendinput, {F5} ; refresh the page - same title
WinWaitClose, Google
MsgBox, success
It will show this message though, could I use it somehow?

Code: Select all

<p class="display">File uploaded successful.</p>
Actually you can take adavntage of the value of this p element, especially if it is specific to the page. However you must get a pointer to the web browser - for example creating an - IE specific - ActiveX control (see also: Basic Webpage Controls with JavaScript / COM - Tutorial)
Simple example:

Code: Select all

; Gui Add, ActiveX, w980 h640 vWB, Shell.Explorer  ; The final parameter is the name of the ActiveX component.
; WB.Navigate("https://www.google.fr/")  ; This is specific to the web browser control.
wb := ComObjCreate("InternetExplorer.Application") ; create IE
wb.Visible := true ; show IE
wb.Navigate("https://www.google.fr/") ; Navigate Google
while (WB.busy or WB.readystate <> 4) ; waits for the page to be loaded
	sleep, 300
Gui Show
return


!i:: ; ALT+I hotkey
WB.document.getElementByID("lst-ib").innerText := "blabla" ; SET the value of the searchbar
	MsgBox % WB.document.getElementsByTagName("p")[0].outerHTML ; GET some value from the page
return

my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Araphen, demon740, mapcarter and 298 guests