rusdady

Browser (IE) HTML document ready event

6 posts in this topic

Hi.

Is there a way in autoit script to wait while browser's html document fully loaded, instead of putting script in Sleep?

I have this code:

        

Sleep(8000)
$oDocument=_UIA_getFirstObjectOfElement($oIE,$cDocumentWindow, $treescope_subtree)
Sleep(8000)

If not isobj($oDocument) Then
   _UIA_DumpThemAll($oIE,$treescope_subtree)
Else
   ......
EndIf

 

I do not like this - Sleep(8000). Sometimes it takes 2 seconds to load, sometimes it takes over 8 seconds...

I would like to have something that would wait when html document is ready/loaded.

Thank you.

Share this post


Link to post
Share on other sites



Thank you! You pointed me to the right direction. The only problem is that when I load page it popups the "Windows Security" window asking for credentials and until credentials entered page is not loading... but I'll give it a try. Thanks anyway!

Share this post


Link to post
Share on other sites

Finally, I ended up with following approach:
 

$oDocument=_UIA_getFirstObjectOfElement($oIE,$cDocumentWindow, $treescope_subtree)
If not isobj($oDocument) Then
    _UIA_DumpThemAll($oIE,$treescope_subtree)
Else
    $t=stringsplit(_UIA_getPropertyValue($oDocument, $UIA_BoundingRectanglePropertyId),";")
    _UIA_DrawRect($t[1],$t[3]+$t[1],$t[2],$t[4]+$t[2])

    ;~loop until button is loaded
    local $oClock =_UIA_getFirstObjectOfElement($oDocument,"id:=TodaysActivities_btnClock", $treescope_subtree)
    While not IsObj($oClock)
        Sleep(500)
        $oClock =_UIA_getFirstObjectOfElement($oDocument,"id:=TodaysActivities_btnClock", $treescope_subtree)
    WEnd

    _UIA_action($oClock,"leftclick")

    Sleep(2000)
    _UIA_action($oIE,"close")
EndIf

I put "while" cycle to check if needed button is loaded. It seems like it is working...

If anyone has better ideas - please welcome to share it... :-)

Share this post


Link to post
Share on other sites

Unfortunatelly, this part

;~loop until button is loaded
    local $oClock =_UIA_getFirstObjectOfElement($oDocument,"id:=TodaysActivities_btnClock", $treescope_subtree)
    While not IsObj($oClock)
        Sleep(500)
        $oClock =_UIA_getFirstObjectOfElement($oDocument,"id:=TodaysActivities_btnClock", $treescope_subtree)
    WEnd

has stopped working.

Script cannot find button by id. And it happend, i believe, after windows 10 update...

 

Share this post


Link to post
Share on other sites

Does anyone know how to get elements of the html page? Whatever I try now nothing is working...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
      Brian
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
    • BOUNCER
      By BOUNCER
      I'm trying to get the output data from https://www.guilded.gg but it uses a web app that generates that output on the fly and this doesn't show up in the page source.
      Only in web inspector of each browser does this data show up. How do I read this data in autoit (equivalent to the web inspector)
       
      thank you
    • ur
      By ur
      We can select elements in IE using their IDs as below.
      Local $oDiv = _IEGetObjById($oIE, "x-auto-16-input") But to one button in the webpage, there is no ID to it.
      In selenium we have option to select this element using the CssSelector and clicked the button using below code in c# selenium.
      driver.FindElement(By.CssSelector("button.x-btn-text")).Click(); What is the alternative for this in AUtoIT?
    • whiskas
      By whiskas
      Hi all,
      I just upgraded to windows 10 and am using Edge as my browser now. Updated my scripts, but I can not unhide a minimized Edge window with the script anymore.
      WinSetState ( "titlle","", @SW_MAXIMIZE ) works fine, but not if it is minimized. Tried same with SW_SHOW, doesn't work.
      WinExists("title","") -> returns 1, so it is finding my window.
       
              WinWait($title,$text,$timeout)
              If Not WinActive($title,$text) Then WinActivate($title,$text)
              WinWaitActive($title,$text,$timeout)
      Doesn't work also, so I think I tried all but cant get the window back
      Any help would be appreciated