[Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No IE!
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Ah, that makes sense. So, "%value%" was probably just a typographical error, intended to be "%val%". I've now made that correction in my copy of Chrome.ahk. Thank you.
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
So yesterday I had a windows update and now my script is not working anymore.
I tracked down to be Chrome.ahk, because even setting up the basic example on github would give me this error:
Image here: https://i.ibb.co/TKbhqWK/Capture.png
Any ideas how to fix it?
I tracked down to be Chrome.ahk, because even setting up the basic example on github would give me this error:
Image here: https://i.ibb.co/TKbhqWK/Capture.png
Any ideas how to fix it?
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
to geekdude, grepster and anyone:
Do you guy know how to make autohotkey work with Opera browser? Thanks
Do you guy know how to make autohotkey work with Opera browser? Thanks
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
@dekinhow, I occasionally see exactly the same error on both Win10 and Win7. It usually means I have an orphaned instance of chrome.exe, chromedriver.exe or both still running. It has been happening a little more often since Chrome updated to version 84.
Regards,
burque505
Regards,
burque505
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
@Balovauto, try the operachromiumdriver. If it doesn't work out-of-the-box with Chrome.ahk, perhaps adapting @GeekDude's script for Firefox portable (link) will work.
Regards,
burque505
Regards,
burque505
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Afaics, the fastest (and easiest) way to re-use Chrome.ahk for other Chromium-based browsers which support the same debug protocol (which includes Opera and the new Edge) would be to just use the path to the browsers's exe as the fourth parameter for Chrome.ahk's new() contructor:
Code: Select all
operaPath := "C:\Users\g\AppData\Local\Programs\Opera\70.0.3728.95\opera.exe"
ChromeInst := new Chrome("OperaProfile", , , operaPath)
But it seems, for Opera, you can also use the more general
Code: Select all
operaPath := "C:\Users\g\AppData\Local\Programs\Opera\launcher.exe"
Code: Select all
#NoEnv
SetBatchLines, -1
SetTitleMatchMode 2
#Include Chrome.ahk ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=42890
url := "https://autohotkey.com" ; url := "https://google.com"
; operaPath := "C:\Users\g\AppData\Local\Programs\Opera\70.0.3728.95\opera.exe"
operaPath := "C:\Users\g\AppData\Local\Programs\Opera\launcher.exe"
; --- Create a new Opera instance ---
FileCreateDir, OperaProfile ; creates a profile subdirectory in current folder
ChromeInst := new Chrome("OperaProfile", , , operaPath)
winwait, – Opera
; --- Connect to the page ---
if !(Page := ChromeInst.GetPage( ))
{
MsgBox, Could not retrieve page!
ChromeInst.Kill()
}
else
Page.WaitForLoad()
Page.Call("Page.navigate", {"url": url}) ; Navigate to url
Page.WaitForLoad()
return
Esc::ExitApp
Please note that this only works, if you plan to start a new Opera debug instance. To detect already running Opera instances (in debug mode) and to connect to them, you would also need to change the hard-coded references in the Findinstances() method in Chrome.ahk (then you could also change the Chrome references in the New() method).
I guess you could either change it in the original class (make a copy) - or create an Opera class which could extend the Chrome class and overwrite the methods that need to be replaced... the rest of the code can simply be re-used. So, only minor changes would be needed
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Thanks, @gregster. Great info.
Regards,
burque505
Regards,
burque505
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Hello all,
My question is so basic that I am a bit embarassed : )
I downloaded the chrome.ahk library and figured out how to also add the two empty subfolders under lib which I am sure there is a better way.
Upon running the include line of the chrome.ahk I get an error on the very line 1 that Class Chrome is unrecognized.
Specifically in 1.2
Error at line 5 in #include file.... chrome.ahk
Line Text: class Chrome
Error: This line does not contain a recognized action.
The program will exit.
I am sure it is something simple/dumb.
Appreciate getting me going
My question is so basic that I am a bit embarassed : )
I downloaded the chrome.ahk library and figured out how to also add the two empty subfolders under lib which I am sure there is a better way.
Upon running the include line of the chrome.ahk I get an error on the very line 1 that Class Chrome is unrecognized.
Specifically in 1.2
Error at line 5 in #include file.... chrome.ahk
Line Text: class Chrome
Error: This line does not contain a recognized action.
The program will exit.
I am sure it is something simple/dumb.
Appreciate getting me going
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Are you running some ancient 1.0.x version of AHK?
Not sure, what this means... are you talking about AHK's local, user or standard library? But which two empty subfolders?figured out how to also add the two empty subfolders under lib which I am sure there is a better way
At least for testing, I would put Chrome.ahk directly into the script's directory...
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Thanks @gregster I was running a 2009 version and have no idea why. I am usually good about upgrading.
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
@pmobin
You get empty/broken files when you download the partial source used to build the library instead of the library itself. See this post from page 1 of the thread:
You get empty/broken files when you download the partial source used to build the library instead of the library itself. See this post from page 1 of the thread:
GeekDude wrote: ↑17 Jan 2018, 07:39Make sure you're downloading the release file "Chrome.ahk_v1.0.zip" from the releases page, not the source code. As you have learned, GitHub does not include submodules (i.e. AutoHotkey-JSON and WebSocket.ahk) in its source downloads. The release has all the #Include's built in (no lib folder needed ).
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Worth mentioning again that the latest release on https://github.com/G33kDude/Chrome.ahk/releases is Chrome.ahk_v1.2.zip and its file Chrome.ahk has a typo. Search for App Pahs\chrome.exe and replace with App Paths\chrome.exe
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Hello guys, I am looking for some clarification before I commit myself in learning to use Chrome.ahk. Specifically for Firefox
I get the impression most people use chrome.ahk to do some web scrapping here and there and then disconnect it and set it aside until next time.
But I am looking to use it as a means of getting AHK to control web “apps” or pages programmatically, including address bar.
For example, to configure AHK hotkeys to toggle the visibility of an element on a website, set the text of a textbox or send a URL to the currents tabs address bar
This would mean a constant connection between Chrome.ahk and FF, a “port” open and having FF running in debug mode.
Is Chrome.ahk meant to be used this way? Can you establish a connection through a port once and just forget about it? (of course, not including computer restarting and sleeping ) Thanks!
I get the impression most people use chrome.ahk to do some web scrapping here and there and then disconnect it and set it aside until next time.
But I am looking to use it as a means of getting AHK to control web “apps” or pages programmatically, including address bar.
For example, to configure AHK hotkeys to toggle the visibility of an element on a website, set the text of a textbox or send a URL to the currents tabs address bar
This would mean a constant connection between Chrome.ahk and FF, a “port” open and having FF running in debug mode.
Is Chrome.ahk meant to be used this way? Can you establish a connection through a port once and just forget about it? (of course, not including computer restarting and sleeping ) Thanks!
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Probably more trouble than its worth but...
I wanted to be able to launch the same chrome page(a local html file) multiple times - without having multiple debug ports open, but yet make sure than each page instance could be interacted with independently. If you arent careful - you will end up connecting to a different instance of your app which is running on the same port.
I also wanted each page that opened to be in 'window' mode. Unfortunately, even in you start chrome with the --app="url" switch, any additional pages you open will NOT be in app mode, so you will show the navigation and url bar, etc. If anyone knows a workaround for this using the devtools protocol, im all ears.
Here is my solution:
First - i modified the _new Constructor slightly in the chrome class to ensure the first Chrome Instance i created was available before i try to connect to the websocketdebugger URL(It would sometimes try to get the pageinstance before it was available on the 127.0.0.1:port:/json endpoint):
All the above does is wait for the PID to exist - if not in 3 seconds, returns -1
Works reliably for the *First* Chrome Instance. After Chrome instance created, i connect to the page via URL
For each subsequent time i open the same app - the above waiting for PID FAILS, because chrome does black magic with the PID it returns after the first instance is created. So, the solution for me was 2 steps:
1. I had to add a 1 second sleep after calling 'ChromeInst := new chrome(...)' - the class constructor would always return too early, and the subsquent GetPageBy calls would fail as the /json endpoint was not ready. Using Sleeps is never ideal - so im all ears to suggestions on this one.
2. To make sure create a temporary copy of my .html file with a new name each time so that you dont need to worry about attaching to the incorrect page:
This way - You can launch several Chrome Instances in seperate scripts - using the same debug port.
I mucked around with this for days - if someone has a better way to launch multiple chrome pages - in APP mode - on the same debug port - please let me know!
Thanks for listening...
I wanted to be able to launch the same chrome page(a local html file) multiple times - without having multiple debug ports open, but yet make sure than each page instance could be interacted with independently. If you arent careful - you will end up connecting to a different instance of your app which is running on the same port.
I also wanted each page that opened to be in 'window' mode. Unfortunately, even in you start chrome with the --app="url" switch, any additional pages you open will NOT be in app mode, so you will show the navigation and url bar, etc. If anyone knows a workaround for this using the devtools protocol, im all ears.
Here is my solution:
First - i modified the _new Constructor slightly in the chrome class to ensure the first Chrome Instance i created was available before i try to connect to the websocketdebugger URL(It would sometimes try to get the pageinstance before it was available on the 127.0.0.1:port:/json endpoint):
Code: Select all
DetectHiddenWindows, On
start := A_TickCount
while !WinExist("ahk_pid" . OutputVarPID){
tooltip % A_TickCount - Start
if(A_TickCount - Start > 3000)
return, -1
}
DetectHiddenWindows, % DHW
Works reliably for the *First* Chrome Instance. After Chrome instance created, i connect to the page via URL
Code: Select all
PageInstance := ChromeInst.GetPageByURL("file:///" StrReplace(Path,"\","/"), "exact",,BoundCallBack)
1. I had to add a 1 second sleep after calling 'ChromeInst := new chrome(...)' - the class constructor would always return too early, and the subsquent GetPageBy calls would fail as the /json endpoint was not ready. Using Sleeps is never ideal - so im all ears to suggestions on this one.
2. To make sure create a temporary copy of my .html file with a new name each time so that you dont need to worry about attaching to the incorrect page:
Code: Select all
Path := A_ScriptDir "\Quote" A_TickCount ".html"
FileRead, htmldoc, % A_ScriptDir "\Quote.html"
FileAppend, % htmldoc, % Path
I mucked around with this for days - if someone has a better way to launch multiple chrome pages - in APP mode - on the same debug port - please let me know!
Thanks for listening...
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Example of what i mean -
3 copies of my app running on the same debug port all in 'app' mode:
https://imgur.com/a/2IU1wAQ
3 copies of my app running on the same debug port all in 'app' mode:
https://imgur.com/a/2IU1wAQ
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
So I was watching the Part 3 of Automating Chrome via the Chrome library video tutorial and the author says I should look out for an imported script, in this case ace.js to look at the documentation of that particular service and see how I can interact with that type of code.
Now I'm on this site with a huge source code (amazon.de) and I have no Idea what to look for.
Maybe in this section it's just java script? (it says javascript on top of the codesection I'm looking at (see pic) but I'm not sure where javascript has to stand to relate to that section)
Perhaps you can help me out when I say what my goal is:
I want to navigate to the search field of an amazon.de page automatically as soon as it loads.
I've used the element picker to find out which code portion it's from and it highlighted:
Then I toggled the device toolbar and discovered that the code portion above the highlighted code changed a word (highlighted in purple, see pic) as I clicked in and outside of the searchbar
to
How would I change that portion of the script with java via the chrome.ahk library?
Btw, how many posts do I need to post links without them getting broken by the messageboard?
Now I'm on this site with a huge source code (amazon.de) and I have no Idea what to look for.
Maybe in this section it's just java script? (it says javascript on top of the codesection I'm looking at (see pic) but I'm not sure where javascript has to stand to relate to that section)
Perhaps you can help me out when I say what my goal is:
I want to navigate to the search field of an amazon.de page automatically as soon as it loads.
I've used the element picker to find out which code portion it's from and it highlighted:
Code: Select all
<input type="text" id="twotabsearchtextbox" value="" name="field-keywords" autocomplete="off" placeholder="" class="nav-input" dir="auto" tabindex="0" aria-label="Search">
Code: Select all
class="nav-searchbar"
Code: Select all
class "nav-searchbar nav-active"
Btw, how many posts do I need to post links without them getting broken by the messageboard?
- Attachments
-
- chrome_2020-09-12_22-31-30.png (34.77 KiB) Viewed 3443 times
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Navigate to the field, and 'activate' it? or do you just want to input some text into it? because you dont need to worry about that classname if you just want to input some text id imagine.
Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!
Hi @ars4l4n, maybe this will help. Seems to be working for me. Quick and dirty, sorry about that.
Regards,
burque505
Code: Select all
#Include Chrome.ahk
ChromeInst := new Chrome("ChromeProfile")
PageInstance := ChromeInst.GetPage()
PageInstance.Call("Page.navigate", {"url": "https://www.amazon.de/"})
PageInstance.WaitForLoad()
Sleep, 1000
PageInstance.Evaluate("document.querySelector(""#twotabsearchtextbox"").value = ""Müller's Esel, Müller's Kuh, usw."";")
Sleep, 5000
PageInstance.Call("Browser.close")
ExitApp
burque505
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: Noitalommi_2 and 170 guests