Chrome library for ahk v2
- ositoMalvado
- Posts: 183
- Joined: 24 Dec 2019, 12:02
- Contact:
Chrome library for ahk v2
Hi guys, does exist CHROME AHK v1.3 for AHKV2?
https://github.com/G33kDude/Chrome.ahk
I use this for v1, but cant find for v2, someone please, thanks!!
https://github.com/G33kDude/Chrome.ahk
I use this for v1, but cant find for v2, someone please, thanks!!
My WEB some useful stuff
Re: Chrome library for ahk v2
well there used to be one for v2 some days ago if memory serves right but geekdude must have deleted the branch for some reason
-
- Posts: 4331
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Chrome library for ahk v2
There is this one, not tested yet.
Re: Chrome library for ahk v2
I tried it, for some reason it doesn't work get lots of errors.
In particular this error
Code: Select all
#Requires AutoHotkey v2.0-a
#SingleInstance Force
#Include <chrome>
chro:=chrome()
page:=chro.GetPage()
url:=page.Evaluate("window.location.href").value
msgbox url
Code: Select all
Error: This value of type "String" has no method named "Evaluate".
005: chro := chrome()
006: page := chro.GetPage()
▶ 007: url := page.Evaluate("window.location.href").value
Re: Chrome library for ahk v2
Ok to answer my question and having fixed it. There is a difference in that now page.evaluate(JS) is a type "Map" hence difference syntax to call the value.
Also, we need JSON.ahk and WebSocket.ahk from
https://github.com/thqby/ahk2_lib
so this final code works for me
if you try this to do it on this page viewforum.php?f=82
You should get "Gaming"
Also, we need JSON.ahk and WebSocket.ahk from
https://github.com/thqby/ahk2_lib
so this final code works for me
Code: Select all
#Requires AutoHotkey v2.0-a
#SingleInstance Force
#Include <Chrome>
#Include <JSON>
xCh:=Chrome()
page:=xCh.GetPage()
url:=page.evaluate("window.location.href")["value"]
msgbox url
Code: Select all
JS:="document.querySelectorAll('dt > div.list-inner > a.forumtitle')[0].innerText"
msgbox page.Evaluate(JS)["value"]
Re: Chrome library for ahk v2
Hi all, I'm struggling to make chrome.ahk work, as so much of the advice is for v1, and I can get a bit stuck translating it into v2. I'm trying to open a new window that chrome.ahk can work with, open a webpage in a new tab, wait for it to load, click a button, and wait for the new page to load. In this example, I've used the sign-in button on google.com
however, WaitForLoad() doesn't seem to work, the script rushes through to the end, and the evaluate/click command is delivered to a still-loading webpage, and so isn't being done. The script works if I replace WaitForLoad() with a sleep command, but I don't want a script that relies on a webpage loading within a guessed duration. It's probably because I don't understand classes well enough, but any advice is much appreciated.
however, WaitForLoad() doesn't seem to work, the script rushes through to the end, and the evaluate/click command is delivered to a still-loading webpage, and so isn't being done. The script works if I replace WaitForLoad() with a sleep command, but I don't want a script that relies on a webpage loading within a guessed duration. It's probably because I don't understand classes well enough, but any advice is much appreciated.
Code: Select all
myURL := "https://www.google.com/"
xCh := Chrome()
Run('"C:\Program Files\Google\Chrome\Application\chrome.exe " --remote-debugging-port=9222 --remote-allow-origins=* --user-data-dir="C:\remote-profile"')
winwait "- Google Chrome"
WinActivate
myPage := xCh.NewPage(myURL)
myPage.WaitForLoad()
myPage.evaluate("document.querySelector('#gb > div > div.gb_0d > a > span').click()")
myPage.WaitForLoad()
;do all the other things I want to do.
Re: Chrome library for ahk v2
Alternative recommendation: https://github.com/Descolada/UIA-v2
Additionally there is UIA_Browser.ahk, which contains helper functions for browser automation (fetching URLs, switching tabs etc). Currently it supports Chrome, Edge, and Firefox.
Additionally there is UIA_Browser.ahk, which contains helper functions for browser automation (fetching URLs, switching tabs etc). Currently it supports Chrome, Edge, and Firefox.
Re: Chrome library for ahk v2
Please note that UIA is a much worse option than Chrome.ahk or Rufaydium, and I recommend it only when those options are not available. It's slower, less reliable, dependent on the browser layout, language, user options etc.emp00 wrote: ↑08 Aug 2023, 09:54Alternative recommendation: https://github.com/Descolada/UIA-v2
Additionally there is UIA_Browser.ahk, which contains helper functions for browser automation (fetching URLs, switching tabs etc). Currently it supports Chrome, Edge, and Firefox.
Re: Chrome library for ahk v2
@Rakkar
.WaitForLoad() seems to work for me. If it doesn't work for you then you could try looping until a certain element on the page is present.
I posted a V2 example in the Chrome.ahk thread that does something similar to what you are trying to do. (link)
This worked for me:
.WaitForLoad() seems to work for me. If it doesn't work for you then you could try looping until a certain element on the page is present.
I posted a V2 example in the Chrome.ahk thread that does something similar to what you are trying to do. (link)
This worked for me:
Code: Select all
#Requires AutoHotkey v2
#SingleInstance Force
#Include Chrome.ahk
#Include JSON.ahk
myURL := "https://www.google.com/"
ChromeProfilePath := A_AppData "\Google\Chrome\MyProfile"
ChromeInstance := Chrome(,,,, ChromeProfilePath)
PageInstance := ChromeInstance.NewPage()
PageInstance.Call("Page.navigate", {url: myURL})
;PageInstance.WaitForLoad()
JS := "document.querySelector('#gb > div > div.gb_Md > a > span')"
; wait for the button to be present
;for k, v in PageInstance.Evaluate(JS) ; Evaluate returns a map.
; MsgBox ">" k "`n>" v
while PageInstance.Evaluate(JS)["subtype"] = "null"
Sleep 100
JS := "document.querySelector('#gb > div > div.gb_Md > a > span').click()"
PageInstance.Evaluate(JS)
ExitApp
; Chrome.ahk for v2 https://github.com/thqby/ahk2_lib/blob/master/Chrome.ahk
; JSON.ahk for v2 https://github.com/thqby/ahk2_lib/blob/master/JSON.ahk