IE connection issues, asking for opinion Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
DanRim
Posts: 82
Joined: 20 Jul 2018, 15:16

IE connection issues, asking for opinion

Post by DanRim » 18 Sep 2020, 07:45

Hi,
Maybe some AHK users had such experience and know how to solve it.
So I trying to connect to IE, sometimes it works, sometimes it does not work. I cant understand where is the problem and why AHK works so strange.
AHK shows that object is 1, but he cant connect to my title and to that window. Does not work Msgbox, % document.title "`r`n" pwb.document.url
I had code which one moment worked fine and later in the day it is junk and does nothing, just gives errors.
If someone had such experience please share how you solved such problem or how how you found solution?
I just want to mention one more time, that code sometimes works some times do not, and I cant understand why.

Code: Select all

#SingleInstance, Force

^o::
pwb := WBGet()
MsgBox, % isObject(pwb)
;~ var := pwb.LocationURL ; -------------------------------------------------------------------------------- Grab URL
;~ MsgBox, %var%
Msgbox, % pwb.document.title "`r`n" pwb.document.url 

Sleep, 100
If !WinExist("DELFI Žinios - Pagrindinis naujienų portalas Lietuvoje - Internet Explorer") ; ------------ Check If SN Window Exist
; or IfWinNotExist, DELFI Žinios 
	{
		MsgBox, SN window does not exist
		return
	} 
else 
	{
		WinMaximize
		WinWaitActive, DELFI Žinios - Pagrindinis naujienų portalas Lietuvoje - Internet Explorer	
	}

;*******************************************************************
while pwb.busy or pwb.ReadyState !=4 ;wait for page to load
	Sleep, 50
;*******************************************************************

Return





; ---------------------------- IE WEB SCRAPPING CONNETION SCRIPT ------------------------------------

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)
      }
   }
}













^+x::ExitApp

Attachments
error1.JPG
sorry for poor quality, was not able to make better
error1.JPG (37.3 KiB) Viewed 112 times
Last edited by DanRim on 18 Sep 2020, 14:54, edited 2 times in total.

gregster
Posts: 5157
Joined: 30 Sep 2013, 06:48

Re: IE connection issues, asking for opinion

Post by gregster » 18 Sep 2020, 11:17

just gives errors.
It might help potentail helpers to know which kind of errors you get.

DanRim
Posts: 82
Joined: 20 Jul 2018, 15:16

Re: IE connection issues, asking for opinion

Post by DanRim » 18 Sep 2020, 11:35

@gregster My bad, I updated post. Thanks for feedback.

User avatar
Xtra
Posts: 1915
Joined: 02 Oct 2015, 12:15

Re: IE connection issues, asking for opinion

Post by Xtra » 18 Sep 2020, 12:23

Msgbox, % document.title "`r`n" pwb.document.url
should be:
Msgbox, % pwb.document.title "`r`n" pwb.document.url

?

HTH

DanRim
Posts: 82
Joined: 20 Jul 2018, 15:16

Re: IE connection issues, asking for opinion

Post by DanRim » 18 Sep 2020, 14:57

@Xtra you are right it is missing pwb. I typed with syntax mistake to this example, my mistake, but in code at my work it is with pwb. I edited now with missing pwb to this example, but I still get error. Maybe you have working example and I will try to reuse it?

User avatar
Xtra
Posts: 1915
Joined: 02 Oct 2015, 12:15

Re: IE connection issues, asking for opinion

Post by Xtra » 18 Sep 2020, 15:06

In the error message you can see its missing the % before document.title

DanRim
Posts: 82
Joined: 20 Jul 2018, 15:16

Re: IE connection issues, asking for opinion  Topic is solved

Post by DanRim » 22 Sep 2020, 08:24

@Xtra Thanks for your suggestions. I found solution by accident. All script is good, but problem was with browsers and active windows. I had opened two IE browsers. That means in my first IE browser I had some stuff with multiple tabs opend and on another IE browser I had one page one tab (Amazon example) to which I wanted to connect. And That was the problem. I closed one IE browsers and merged tabs into one browser. So all IE active windows were opened on one IE browser, i just had more tabs then. It seems that AHK was messing around, because of that.

Post Reply

Return to “Ask For Help”