But your class iWebBrowser2 does not contain such property. Can you explain in more detail?
Click on specific button of existing web page.
-
- Posts: 4326
- 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
}
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;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
-
- Posts: 4326
- 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: 4326
- Joined: 29 Mar 2015, 09:41
- 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;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
-
- Posts: 4326
- 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: 4326
- 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
Re: Click on specific button of existing web page.
Thank you for yours very useful and complex codes. I would like to emphasize very useful complex .ahk library which uses also some WIndows library calls to access WEB elements. You could even use those techniques to create screen readers in Autohotkey by browsing Internet WEB page to create virtual buffer. I have big plea to you. How to activate some link with Play name, which do not contain direct link, it is link to activate HTML5 player. By other words, I would had to find Play link and simulate clicking on it. But it has hook. Internet Explorer page window is hydden and page is loaded before I would want to activate Play link. The question is, if is it possible to click on WEB element, if IE WIndow is hydden with no need to unhyde it. I AM constructing Internet radio player, which call official WEB site. I do not want to determine real streams link, since it is not wanted by many radio stations prowiders, it is causing hydden war between users and streaming servers admins, who are monitoring access protocols and I do not want to go by this way. i want to discuss with official streams dedevelopers instead so they would give Me permissions to use their official pages without hacking direct sstreams links. The reason, whx I AM constructing The alternate GUI to control their pages? Severly physically impaired people who has also sighted problems have issues when pressing keys for many times while using official sites.
I will respect licensesconditions of streams prowiders.
But how to click on Play link, it is link which do not contain some real link to copy by using contex menu. Or should I rather try to use Javascript to click on it, if IE window is hydden?
I will respect licensesconditions of streams prowiders.
But how to click on Play link, it is link which do not contain some real link to copy by using contex menu. Or should I rather try to use Javascript to click on it, if IE window is hydden?
-
- Posts: 4326
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Click on specific button of existing web page.
@Janusz
It's possible, but it depends on a web page.
It's possible, but it depends on a web page.
Code: Select all
html =
(
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
<body>
<script>function showAlert(e) { e.preventDefault(); alert("the link was clicked!"); }</script>
<a href="" onclick="showAlert(event)">Click Me</a>
</body>
</html>
)
IE := ComObjCreate("InternetExplorer.Application")
OnExit( Func("Exit").Bind(IE) )
IE.Visible := false
IE.navigate("about:blank")
while IE.busy
continue
IE.document.write(html)
IE.document.querySelector("a").click()
Exit(IE) {
try IE.Quit()
}