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 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
       
    • 5ervant
      By 5ervant
      Go create a quick account in Zapier and go to https://zapier.com/app/dashboard and make some Zaps!
      Just need to click the specific instance of an .open-menu button and then click its a.run (anchor) element.
      Doing this IE.au3 script just causing to click its container element:
      $target = 1; Target the first instance #include <IE.au3> $oIE = _IEAttach("Dashboard - Zapier") $count = 0; $tags = _IETagNameGetCollection($oIE, "div") For $tag in $tags $class_value = $tag.GetAttribute("class") If $class_value = "open-menu" Then $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) ; $tag.fireEvent("onmousedown") ; _IEAction($tag, "click") ; $tag.fireEvent("onmouseup") ; Or this but not working ; $tag.Click EndIf EndIf Next I also tried to do it using FF.au3
      $target = 1; Target the first instance #Include <Array.au3> #Include <FF.au3> $count = 0; If _FFConnect(Default, Default, 3000) Then $aArray = _FFXPath( "//div[@class='open-menu']", "", 7 ) ; _ArrayDisplay($aArray) For $tag in $aArray $count += 1 if $count = $target Then MsgBox(0, "Instance: ", $count) _FFClick($tag) EndIf Next EndIf Error: _FFClick ==> No match: $sElement: [number]
      Could some help me how to click such buttons on such kind of a dynamic page?