how can I start loading a webpage and then wait until certain text appears on the screen/within the document

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lacrosse1991
Posts: 2
Joined: 28 Jan 2016, 17:32

how can I start loading a webpage and then wait until certain text appears on the screen/within the document

28 Jan 2016, 17:37

Hello,

How can I start loading a webpage and then make my script wait until certain text appears in the webpage?

I tried using com at first, but the webpage will finish loading before the content actually appears on the webpage.

This is what I initially tried (this method just waited for the page finish loading)

Code: Select all

ie := comobjcreate("internetexplorer.application")
ie.navigate("https://itsm..com/sm/index.do?ctx=docEngine&file=probsummary&query=number%3D%22IM102621301%22&action=&title=Incident%20IM102621301")
While ie.busy
    Sleep 10
ie.visible := true
MsgBox The page is done loading.
User avatar
Xeo786
Posts: 750
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: how can I start loading a webpage and then wait until certain text appears on the screen/within the document

29 Jan 2016, 00:22

:ugeek: I have same issue following code didn't work for me when I run event onchange, :(

Code: Select all

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10
there was some java elements involved, coz webpage didn't refresh but page take time to retrieve data when I hit onchange event...
and there was text appear on screen saying.... "Loading.... please wait" :idea:

so I took screen shot of that, corp image, showing only "it" from "wait" that "it" was quite unique :HeHe: so I applied image search to wait until that text stay on screen

Code: Select all

sleep 100
Loop 
{
CoordMode Pixel, screen
ImageSearch, imageX, imageY, 0, 0, A_ScreenWidth, A_ScreenHeight, *TransWhite D:\loading\loading_it.png 
if (imageY > 1) 
{
sleep 100
}
else if (imageY == "")
Break
}
sleep 100
I was really confuse to figure out how to search image that is transparent. :think:
then I saw " *TransWhite" :geek:
that worked for me :superhappy:
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Facebook: socialjsz
Google: +Jszapp
Location: Denmark
Contact:

Re: how can I start loading a webpage and then wait until certain text appears on the screen/within the document

29 Jan 2016, 09:22

fyi - Some pages use javascript or ajax or some other method to create elements after the page load is complete

one way to check for them is to

do the normal load wait like in the OP's example and then use something like this

Code: Select all

loaded := false
While !loaded
{
    try
    {
        if (ie.document.getElementById("some_ID").innertext != "")
            loaded := true
    }
    Sleep 100
}
Hope it helps
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
lacrosse1991
Posts: 2
Joined: 28 Jan 2016, 17:32

Re: how can I start loading a webpage and then wait until certain text appears on the screen/within the document

29 Jan 2016, 14:10

Blackholyman wrote:fyi - Some pages use javascript or ajax or some other method to create elements after the page load is complete

one way to check for them is to

do the normal load wait like in the OP's example and then use something like this

Code: Select all

loaded := false
While !loaded
{
    try
    {
        if (ie.document.getElementById("some_ID").innertext != "")
            loaded := true
    }
    Sleep 100
}
Hope it helps
Hi, thanks! I was actually looking at this and unfortunately it looks like the IDs for the elements change whenever the page is updated. For example, I am trying to wait for a save button to show up:

<button type="button" id="ext-gen334" class=" x-btn-text" aria-label="Save (Ctrl+Shift+F4)" style="background-image: url("images/toolbar/tsave.png");">Save</button>

All of those details will stay the same but the ID/name will have a different number at the end, say ext-gen334 for example. Would it be possible to get an element by its aria label, link text, etc?
Arbab Irfan wrote::ugeek: I have same issue following code didn't work for me when I run event onchange, :(

Code: Select all

While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10
there was some java elements involved, coz webpage didn't refresh but page take time to retrieve data when I hit onchange event...
and there was text appear on screen saying.... "Loading.... please wait" :idea:

so I took screen shot of that, corp image, showing only "it" from "wait" that "it" was quite unique :HeHe: so I applied image search to wait until that text stay on screen

Code: Select all

sleep 100
Loop 
{
CoordMode Pixel, screen
ImageSearch, imageX, imageY, 0, 0, A_ScreenWidth, A_ScreenHeight, *TransWhite D:\loading\loading_it.png 
if (imageY > 1) 
{
sleep 100
}
else if (imageY == "")
Break
}
sleep 100
Thanks! I think I may give blackholyman's suggestion a try first but I planning on giving this a go if I'm not able to get his solution to work.
User avatar
Xeo786
Posts: 750
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: how can I start loading a webpage and then wait until certain text appears on the screen/within the document

02 Feb 2016, 06:51

Blackholyman wrote:fyi - Some pages use javascript or ajax or some other method to create elements after the page load is complete

one way to check for them is to

do the normal load wait like in the OP's example and then use something like this

Code: Select all

loaded := false
While !loaded
{
    try
    {
        if (ie.document.getElementById("some_ID").innertext != "")
            loaded := true
    }
    Sleep 100
}
Hope it helps

Yes you did helped me, normal load worked only for in dropdownlist, and there was so many dorpdownboxs and I was failed, now I get how to wait for java :salute:
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: EmmaEmily, Evil-e, Joey5, mikeyww and 63 guests