But your class iWebBrowser2 does not contain such property. Can you explain in more detail?
Click on specific button of existing web page.
-
- Posts: 2057
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Click on specific button of existing web page.
What do You mean by "frames"?
Can You give example when IEGet() will not work with existing DOM of IE?
Code: Select all
Pwb:= ComObjCreate( "InternetExplorer.Application" )
Pwb.Navigate("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols")
Pwb.Visible:= True
While ( Pwb.Busy || Pwb.ReadyState != 4 )
Sleep 10
msgbox page loaded
oIE := IEGet()
msgbox % oIE.document.documentElement.OuterHtml
iFrame := ComObject( 9, ComObjQuery(oIE.document.parentWindow.frames["iframeResult"],"{332C4427-26CB-11D0-B483-00C04FD90119}","{332C4427-26CB-11D0-B483-00C04FD90119}"), 1)
msgbox % iFrame[0].document.documentElement.OuterHtml
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ;// Get active window if no parameter
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
- tank
- Posts: 2853
- Joined: 28 Sep 2013, 22:15
- Facebook: charlie.simmons.7334
- Google: ttnnkkrr
- GitHub: ttnnkkrr
- Location: Irving TX
- Contact:
Re: Click on specific button of existing web page.
pDoc(oIE) queries the parent window from the document objectteadrinker wrote: ↑26 Jul 2019, 19:13But your class iWebBrowser2 does not contain such property. Can you explain in more detail?
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank

-
- Posts: 2057
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Click on specific button of existing web page.
But your code does not return the parent window from the document object, it returns oIE which is oIE := window, which is obtained by enumerating ComObjCreate("Shell.Application").Windows. Am I wrong?
@malcev
The same without object query:
Code: Select all
Pwb:= ComObjCreate( "InternetExplorer.Application" )
Pwb.Navigate("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols")
Pwb.Visible:= True
While ( Pwb.Busy || Pwb.ReadyState != 4 )
Sleep 10
msgbox page loaded
oIE := IEGet()
parentFrame := oIE.document.getElementById("iframeResult")
MsgBox, % parentFrame.contentDocument.querySelector("[src='frame_a.htm']").contentDocument.documentElement.OuterHtml
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ;// Get active window if no parameter
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
Re: Click on specific button of existing web page.
teadrinker, Your method works not always.
Try to get this iframe with contentDocument:
Try to get this iframe with contentDocument:
Code: Select all
Pwb:= ComObjCreate( "InternetExplorer.Application" )
Pwb.Navigate("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#Example2")
Pwb.Visible:= True
While ( Pwb.Busy || Pwb.ReadyState != 4 )
Sleep 10
oIE := IEGet()
iFrame := ComObject( 9, ComObjQuery(oIE.document.parentWindow.frames["frame_Example2"],"{332C4427-26CB-11D0-B483-00C04FD90119}","{332C4427-26CB-11D0-B483-00C04FD90119}"), 1)
msgbox % iFrame[0].document.documentElement.OuterHtml
IEGet(name="") {
IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ;// Get active window if no parameter
Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft)? ?Internet Explorer$")
for wb in ComObjCreate("Shell.Application").Windows()
if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
return wb
}
-
- Posts: 2057
- Joined: 29 Mar 2015, 09:41
- Contact:
- tank
- Posts: 2853
- Joined: 28 Sep 2013, 22:15
- Facebook: charlie.simmons.7334
- Google: ttnnkkrr
- GitHub: ttnnkkrr
- Location: Irving TX
- Contact:
Re: Click on specific button of existing web page.
yes you are wrong
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
https://www.facebook.com/ahkscript.org
If you have forum suggestions please submit a pull request
Check Out WebWriter
Thanks Tank

-
- Posts: 2057
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Click on specific button of existing web page.
?teadrinker wrote: ↑Is there a way to see the difference between my window and yours?
Re: Click on specific button of existing web page.
Interesting discussion of the extended topic.
@Toni Osuna:
Using tank's function:
Using Jethrow's function:
@Toni Osuna:
Using tank's function:
Code: Select all
#NoEnv
#SingleInstance, Force
;url := "https www.google.com /" ;Broken Link for safety
url := "https://www.google.com/"
IfWinNotExist, ahk_class IEFrame
{
Run, iexplore.exe %url%,,, PID
WinWait, ahk_pid %PID%,, 5
} else {
WinActivate, ahk_class IEFrame
WinWaitActive, ahk_class IEFrame
;WinGetActiveTitle, ieWinTitle ; didn't work using "title"
ControlGetText, url, Edit1, ahk_class IEFrame ; to get url programmatically see https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702
}
start := A_TickCount
while !(wb := GetIePagePwb("url", url)) && A_TickCount - start < 10000
Sleep, 25
if !wb {
MsgBox, Failed to get wb object by url
Return
}
wb.Navigate("https://www.autohotkey.com/", navOpenInNewTab := 2048)
wb := ""
start := A_TickCount
while !(wb := GetIePagePwb("title", "AutoHotkey")) && A_TickCount - start < 10000
Sleep, 25
if !wb {
MsgBox, Failed to get wb object by title
Return
}
While (wb.document.getElementsByClassName("mbr-buttons__btn").(1).InnerText != "Forums")
Sleep, 25
wb.document.getElementsByClassName("mbr-buttons__btn").(1).Click() ;Autohotkey forums button (searched by Class)
Return
GetIePagePwb(param, value) {
if !(param ~= "i)^(url|title)$")
throw Exception("Pameter " . param . " not supported")
nil:="", (param = "url" && param := "LocationURL")
for window in ComObjCreate("Shell.Application").Windows {
WinGetClass, winClass, % "ahk_id" window.hwnd
if (winClass != "IEFrame")
continue
try doc := window.document
catch
break
obj := {LocationURL: window, title: doc}[param]
if (obj[param] = value && found := true)
break
}
if found
Return window
}
Code: Select all
#NoEnv
#SingleInstance, Force
;url := "https www.google.com /" ;Broken Link for safety
url := "https://www.google.com/"
IfWinNotExist, ahk_class IEFrame
{
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate( url )
} else {
WinActivate, ahk_class IEFrame
WinWaitActive, ahk_class IEFrame
wb := pwb_get()
}
wb.Navigate("https://www.autohotkey.com/", navOpenInNewTab := 2048)
while !WinActive("AutoHotkey")
sleep, 25
wb := pwb_get()
While (wb.document.getElementsByClassName("mbr-buttons__btn").(1).InnerText != "Forums")
Sleep, 25
wb.document.getElementsByClassName("mbr-buttons__btn").(1).Click() ;Autohotkey forums button (searched by Class)
Return
PWB_Get(WinTitle="A", Svr#=1) ; Jethrow - http://www.autohotkey.com/board/topic/47052-basic-webpage-controls-with-javascript-com-tutorial/
{
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)
}
}
MsgBox, 262160, %A_ScriptName% - %A_ThisFunc%(): Error, Unable to obtain browser object (PWB) from window:`n`n%WinTitle%
}
Re: Click on specific button of existing web page.
Thank you for this code.Using:Code: Select all
url := "https www.google.com /" Broken Link for safety Run, iexplore.exe %url%,,, PID WinWait, ahk_pid %PID% start := A_TickCount while !(wb := GetIePagePwb("url", url)) && A_TickCount - start < 10000 Sleep, 100 if !wb { MsgBox, Failed to get wb object by url Return } wb.Navigate("https://www.autohotkey.com/", navOpenInNewTab := 2048) wb := "" start := A_TickCount while !(wb := GetIePagePwb("title", "AutoHotkey")) && A_TickCount - start < 10000 Sleep, 100 if !wb { MsgBox, Failed to get wb object by title Return } wb.document.getElementsByClassName("mbr-buttons__btn").(1).Click() GetIePagePwb(param, value) { if !(param ~= "i)^(url|title)$") throw Exception("Pameter " . param . " not supported") (param = "url" && param := "LocationURL") for window in ComObjCreate("Shell.Application").Windows { WinGetClass, winClass, % "ahk_id" window.hwnd if (winClass != "IEFrame") continue try doc := window.document catch break obj := {LocationURL: window, title: doc}[param] if (obj[param] = value && found := true) break } if found Return window }
Btw, How to do this on Chrome ?
-
- Posts: 2057
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Click on specific button of existing web page.
This requires a different, more complex approach.
Chrome.ahk
Chrome.ahk
Re: Click on specific button of existing web page.
Did you ever find a working script to click on a button of an existing webpage? I am very new to coding and would appreciate seeing a full example of such a script. The last script I see brings up a new page, but I want to click on a button of a existing webpage already on my screen. Thanks for your help
Who is online
Users browsing this forum: AHKStudent, Albireo, effel, HiSoKa and 48 guests