IE scripts, 1 works, the other doesn't.

Get help with using AutoHotkey and its commands and hotkeys
rynsp8
Posts: 39
Joined: 30 Jan 2018, 12:45

IE scripts, 1 works, the other doesn't.

16 Feb 2018, 15:25

I have two scripts that I'm attempting to manipulate the same website. One works as expected, the other doesn't, and they're essentially to do the same thing.

My first script, will work with an already open IE window and it works exactly as I need it to. However, I want this to pull the data without having the window open.

Code: Select all

#Persistent
#SingleInstance Force
#NoEnv
;*****************************************************************************

pwb := WBGet()


t:=pwb.document.getElementById("2752")
d:=t.getElementsByTagName("td")[1].click()
sleep, 2000
b:=pwb.document.getElementById("secretView_2752")
r:=b.getElementsByTagName("a")[3].click()
sleep, 2000

MsgBox % clipboard


;************Pointer to Open IE Window******************
WBGet(WinTitle="ahk_class IEFrame", Svr#=1) {               ;// based on ComObjQuery docs
   static msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
        , IID := "{0002DF05-0000-0000-C000-000000000046}"   ;// IID_IWebBrowserApp
;//     , IID := "{332C4427-26CB-11D0-B483-00C04FD90119}"   ;// IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%

   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
}
So, I am attempting to do the same in the script below, but I want the process to happen in the background.

Code: Select all

pwb:= ComObjCreate("InternetExplorer.Application")
pwb.Visible:= true
pwb.ToolBar:= false
pwb.Navigate("https://valid-website")
sleep, 5000


;pwb.document.getElementById("gb_70").click()
t:=pwb.document.getElementById("2752")
d:=t.getElementsByTagName("td")[1].click()
;sleep, 2000
;b:=pwb.document.getElementById("secretView_2752")
;r:=b.getElementsByTagName("a")[3].click()

MsgBox, Did this work?

Return
however, it's not working as I expected. It throws an error referencing the first 'document'... if I use Google, pwb.document.getElementById("gb_70").click() works fine...

Any thoughts?

Return to “Ask For Help”

Who is online

Users browsing this forum: A_Perry_1984, AmDeG 11, blad4, Elaphe666, Hellbent, MannyKSoSo and 48 guests