With the "death" of IE I have seen more then ever the need to move to chrome while not losing our love for AHK. I have made a few videos I hope will help others with moving to chrome. I know there are some post here talking about some of these but didn't seem to find a one stop spot with multiple ways ENJOY!
Selenium tends to be a popular way and by far my favorite way in AHK Chrome. Sadly if you work at a large company with a lot of IT security stuff as I do this may not work for you. Need Admin access. This is also great for other browsers other then just chrome.
Selenium = [youtube]https://www.youtube.com/watch?v=_Di0q7nB6MA&t=7s[/youtube]
Since I was unable to use Selenium I Checked out using the chrome Console. This way will open then hide the console so you don't have to deal with seeing it all the time(its like its not even there!). Then you can preform most actions you miss from IE COMs by using some basic JavaScript which I cover some basic JS in the video to get you started.
Chrome Console = [youtube]https://www.youtube.com/watch?v=2Z7X7IjHucM&list=PLfHPAKSz_DJpRd-XB71oTwN-iahluit-X&index=5&t=6s[/youtube]
In the long run I ended up finding a really nice chrome extension called Auto Control Manager. This cool tool helped me to work with AHK and Chrome in a super simple way. The great benefit to this also was a lot of things I would have normally coded into AHK I could do with in the ext with a few simple clicks and no code needed. This way was a great way to keep my AHK simple and sort.
Auto Control = [youtube]https://www.youtube.com/watch?v=gr4z0Xw8W2g&t=86s[/youtube]
Another well know way is by using Chrome.AHK which I have not done a video on but you should still check out here. Hopefully Ill get around to this one day.
Chrome.AHK = [youtube]https://www.autohotkey.com/boards/viewtopic.php?t=42890[/youtube]
Simplest Way With Out Admin Rights or Installing Anything Outside of AHK but not the best but hey if all else fails
sends =[youtube] https://www.youtube.com/watch?v=2DfaTWNkU7I&t=4s[/youtube]
Let me know if you think of any other ways you have seen AHK used with Chrome. As I add video with AHK and Chrome I will be sure to update this post as time goes on.
Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
Last edited by tadamm on 16 Feb 2021, 16:30, edited 1 time in total.
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
I think an additional option is missing, thus will fall under "Other". That is using the RunJsFromChromeAddressBar function. This has a lot of potential as a minimalist and all AHK coding method, that doesn't require 3rd party extensions. References to this option:
https://www.autohotkey.com/boards/viewtopic.php?p=326962#p326962
(Detect clickable link in Chrome)
https://www.autohotkey.com/boards/viewtopic.php?p=362634#p362634
(AHK with Chrome extension (No Selenium, no debug mode, no web connectors)
A major factor is you have to learn some JavaScript (js), in order to do different tasks or have pre-coded JavaScript in a function for a particular task dealing with web pages. There is almost no way around needing to learn some JavaScript because that is the default language of web browsers and often the code you need to automate a specific web page can be different.
You could use image search, OCR, and or shortcut keys for the web browser instead. Some competing automation tools are entirely image based. These methods are somewhat doable and usable, if the task is simple. However, those methods will be problematic for more complicated tasks (like getting certain data out of web pages), greater precision, and when trying to use the script on multiple computers.
Even if we had an Open-Source AutoHotkey extension for Chrome and Edge (this includes the 3rd party extension AutoControl), it would still require that the AHK Coder know some JavaScript and about CSS Selectors. Though I do want to make it clear that I'm in no way against a possible AutoHotkey extension, which could make things easier. AutoControl is 3rd party, Closed-Source, and requires various permissions. So the privacy concerns have to be weighed against its benefits (which I agree it has some).
Another extension/add-on to look at for Chrome, Edge, and Firefox is SelectorsHub, https://selectorshub.com/ or find it more directly like at the Chrome web store. This tool makes it much easier to find the CSS Selector, XPath, or JS Path for a visual object on a web page to be used with a script. This is similar to a feature that many RPA tools have built-in. The CSS Selector for what is wanted on the web page can then be more easily placed into the JavaScript portion of the script.
Example of the RunJsFromChromeAddressBar function
https://www.autohotkey.com/boards/viewtopic.php?p=326962#p326962
(Detect clickable link in Chrome)
https://www.autohotkey.com/boards/viewtopic.php?p=362634#p362634
(AHK with Chrome extension (No Selenium, no debug mode, no web connectors)
A major factor is you have to learn some JavaScript (js), in order to do different tasks or have pre-coded JavaScript in a function for a particular task dealing with web pages. There is almost no way around needing to learn some JavaScript because that is the default language of web browsers and often the code you need to automate a specific web page can be different.
You could use image search, OCR, and or shortcut keys for the web browser instead. Some competing automation tools are entirely image based. These methods are somewhat doable and usable, if the task is simple. However, those methods will be problematic for more complicated tasks (like getting certain data out of web pages), greater precision, and when trying to use the script on multiple computers.
Even if we had an Open-Source AutoHotkey extension for Chrome and Edge (this includes the 3rd party extension AutoControl), it would still require that the AHK Coder know some JavaScript and about CSS Selectors. Though I do want to make it clear that I'm in no way against a possible AutoHotkey extension, which could make things easier. AutoControl is 3rd party, Closed-Source, and requires various permissions. So the privacy concerns have to be weighed against its benefits (which I agree it has some).
Another extension/add-on to look at for Chrome, Edge, and Firefox is SelectorsHub, https://selectorshub.com/ or find it more directly like at the Chrome web store. This tool makes it much easier to find the CSS Selector, XPath, or JS Path for a visual object on a web page to be used with a script. This is similar to a feature that many RPA tools have built-in. The CSS Selector for what is wanted on the web page can then be more easily placed into the JavaScript portion of the script.
Example of the RunJsFromChromeAddressBar function
Code: Select all
ClickLink("Gmail")
Return
ClickLink(LinkText, exe := "msedge.exe")
{
js =
(LTrim
(() =>
{
const links = document.links;
for (let i = 0; i < links.length; i++)
{
if (links[i].innerText == '%LinkText%')
{
links[i].click();
break
}
}
})();
)
RunJsFromChromeAddressBar(js, exe)
}
RunJsFromChromeAddressBar(js, exe := "msedge.exe")
{
static WM_GETOBJECT := 0x3D
, ROLE_SYSTEM_TEXT := 0x2A
, STATE_SYSTEM_FOCUSABLE := 0x100000
, SELFLAG_TAKEFOCUS := 0x1
, AccAddrBar
if !AccAddrBar {
window := "ahk_class Chrome_WidgetWin_1 ahk_exe " . exe
SendMessage, WM_GETOBJECT, 0, 1, Chrome_RenderWidgetHostHWND1, % window
AccChrome := AccObjectFromWindow( WinExist(window) )
AccAddrBar := SearchElement(AccChrome, {Role: ROLE_SYSTEM_TEXT, State: STATE_SYSTEM_FOCUSABLE})
}
AccAddrBar.accValue(0) := "javascript:" . js
AccAddrBar.accSelect(SELFLAG_TAKEFOCUS, 0)
ControlSend,, {Enter}, % window, Chrome Legacy Window
}
SearchElement(parentElement, params)
{
found := true
for k, v in params {
try {
if (k = "ChildCount")
(parentElement.accChildCount != v && found := false)
else if (k = "State")
(!(parentElement.accState(0) & v) && found := false)
else
(parentElement["acc" . k](0) != v && found := false)
}
catch
found := false
} until !found
if found
Return parentElement
for k, v in AccChildren(parentElement)
if obj := SearchElement(v, params)
Return obj
}
AccObjectFromWindow(hWnd, idObject = 0)
{
static IID_IDispatch := "{00020400-0000-0000-C000-000000000046}"
, IID_IAccessible := "{618736E0-3C3D-11CF-810C-00AA00389B71}"
, OBJID_NATIVEOM := 0xFFFFFFF0, VT_DISPATCH := 9, F_OWNVALUE := 1
, h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
VarSetCapacity(IID, 16), idObject &= 0xFFFFFFFF
DllCall("ole32\CLSIDFromString", "Str", idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, "Ptr", &IID)
if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject, "Ptr", &IID, "PtrP", pAcc) = 0
Return ComObject(VT_DISPATCH, pAcc, F_OWNVALUE)
}
AccChildren(Acc)
{
static VT_DISPATCH := 9
Loop 1 {
if ComObjType(Acc, "Name") != "IAccessible" {
error := "Invalid IAccessible Object"
break
}
try cChildren := Acc.accChildCount
catch
Return ""
Children := []
VarSetCapacity(varChildren, cChildren*(8 + A_PtrSize*2), 0)
res := DllCall("oleacc\AccessibleChildren", "Ptr", ComObjValue(Acc), "Int", 0
, "Int", cChildren, "Ptr", &varChildren, "IntP", cChildren)
if (res != 0) {
error := "AccessibleChildren DllCall Failed"
break
}
Loop % cChildren {
i := (A_Index - 1)*(A_PtrSize*2 + 8)
child := NumGet(varChildren, i + 8)
Children.Push( (b := NumGet(varChildren, i) = VT_DISPATCH) ? AccQuery(child) : child )
( b && ObjRelease(child) )
}
}
if error
ErrorLevel := error
else
Return Children.MaxIndex() ? Children : ""
}
AccQuery(Acc)
{
static IAccessible := "{618736e0-3c3d-11cf-810c-00aa00389b71}", VT_DISPATCH := 9, F_OWNVALUE := 1
try Return ComObject(VT_DISPATCH, ComObjQuery(Acc, IAccessible), F_OWNVALUE)
}
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
@SOTE, good call. I use RunJsFromChromeAddressBar and SelectorsHub both quite a bit. SeleniumBasic 3.141.0.0 is an option I'm working on, you might have a look here.
-
- Posts: 639
- Joined: 03 Dec 2018, 20:02
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
I've been using using puppeteer/playwright lately and it worked really well.
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
with AutoHotkey (which would the subject of this topic) ? I thought that would rather be a node.js thing.
But afaik, Puppeteer depends on the same chrome debugging protocol like Chrome.ahk and Selenium in order to automate Chrome.
The individual syntaxes of the front-end packages obviously differ... especially Chrome.ahk could use a few more high-level methods to choose from. Currently, I still have to dig around a lot in the protocol docs at Google, if I want to do something browser-specific (javascript execution is more straightforward, though).
-
- Posts: 639
- Joined: 03 Dec 2018, 20:02
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
Yes it's a node.js thing. Not the most memory efficient but it's a lot faster than Chrome.ahk (which is quite fascinating as well). I think the Google team is doing some black magic since it's their browser.gregster wrote: ↑21 Feb 2021, 08:46with AutoHotkey (which would the subject of this topic) ? I thought that would rather be a node.js thing.
But afaik, Puppeteer depends on the same chrome debugging protocol like Chrome.ahk and Selenium in order to automate Chrome.
The individual syntaxes of the front-end packages obviously differ... especially Chrome.ahk could use a few more high-level methods to choose from. Currently, I still have to dig around a lot in the protocol docs at Google, if I want to do something browser-specific (javascript execution is more straightforward, though).
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
Yeah, Chrome.ahk has probably a few speed bottlenecks in terms of its websocket and json interfaces - but at least for the latter there is an alternative version by teadrinker which should be a bit faster.william_ahk wrote: ↑22 Feb 2021, 05:43Yes it's a node.js thing. Not the most memory efficient but it's a lot faster than Chrome.ahk (which is quite fascinating as well). I think the Google team is doing some black magic since it's their browser.
And yes, the underlying chrome debugging protocol (created by Google) is huge and covers a lot of things, much more than simple DOM manipulation. But since the new Edge and Opera also support it (both are also Chromium-based) it's great to be able to use the same syntax for their automation.
-
- Posts: 639
- Joined: 03 Dec 2018, 20:02
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
About the the alternative version by teadrinker, are you referring to RunJsFromChromeAddressBar or is there a more direct way of interacting with devtools protocol using AHK?gregster wrote: ↑22 Feb 2021, 06:15Yeah, Chrome.ahk has probably a few speed bottlenecks in terms of its websocket and json interfaces - but at least for the latter there is an alternative version by teadrinker which should be a bit faster.
And yes, the underlying chrome debugging protocol (created by Google) is huge and covers a lot of things, much more than simple DOM manipulation. But since the new Edge and Opera also support it (both are also Chromium-based) it's great to be able to use the same syntax for their automation.
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
That is also a very useful function, but in this case I meant a version of Chrome.ahk in which teadrinker replaced the json component to make it faster. I think this is the latest:william_ahk wrote: ↑26 Feb 2021, 02:11About the the alternative version by teadrinker, are you referring to RunJsFromChromeAddressBar or is there a more direct way of interacting with devtools protocol using AHK?gregster wrote: ↑22 Feb 2021, 06:15Yeah, Chrome.ahk has probably a few speed bottlenecks in terms of its websocket and json interfaces - but at least for the latter there is an alternative version by teadrinker which should be a bit faster.
And yes, the underlying chrome debugging protocol (created by Google) is huge and covers a lot of things, much more than simple DOM manipulation. But since the new Edge and Opera also support it (both are also Chromium-based) it's great to be able to use the same syntax for their automation.
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=42890&p=376782#p382756
Re: Multiple Ways to Automate Chrome with AHK. Selenium, Console, Chrome ext. Chrome.AHK
Please add Rufaydium to poll
viewtopic.php?f=6&t=102616
viewtopic.php?f=6&t=102616
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
Who is online
Users browsing this forum: No registered users and 28 guests