[Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by w0z » 12 Sep 2018, 19:03

euras wrote:It may sound stupid, but I'm not a Chrome user and I dont have a clue how do I need to start Chrome in Debug mode? Can someone tell me or give a link where it's showed up?


Hi, you can add --remote-debugging-port=9222 on a shortcut properties after "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" or wherever you chrome path is for you.

In this topic are more about how to configure Debug Mode.
https://autohotkey.com/boards/viewtopic.php?t=32323&start=20#p181299

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by euras » 12 Sep 2018, 15:10

It may sound stupid, but I'm not a Chrome user and I dont have a clue how do I need to start Chrome in Debug mode? Can someone tell me or give a link where it's showed up?

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by mgroen » 24 Aug 2018, 10:37

is this framework also suitable for steering multiple Chrome sessions in parralell?
(for example: to simulate multiple users on a website).

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by GeekDude » 24 Aug 2018, 09:59

ocnuybear wrote:Can Chrome.ahk be compiled into a stand alone DLL & called from 3rd party software?

No, that's what Selenium is. There are other tutorials on this forum for using Selenium with AHK as the 3rd party software, but you can use it with any programming language.

Koiu wrote:How to wait until all elements visible?

I try everything but i dont know how to make my script wait until all elements visible
- I try "PageInst.Evaluate("document.readyState")" to make sure the state page is " Complete" but the button still loading
- i try " PageInst.WaitForLoad()" and the button still loading

i really appreciate if anyone can help me. Thanks

I'm not sure what the exact rules chrome uses are for showing the button in a loading state, but typically the approach you want to take in this situation is to wait for the elements you want to interact to have finished loading. Depending on how the page is built the way to do this can very a lot.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by GeekDude » 24 Aug 2018, 09:41

mgroen wrote:Hi, I'm new to automating Chrome with Autohotkey. If I run this script (see below), I get the error "Websocket.ahk cannot be opened"

Anybody able to assist me?

Make sure you're downloading the release file "Chrome.ahk_vX.Y.zip" from the releases page, not the source code. As you have noticed, 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.

Image
(image from old release)

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by mgroen » 24 Aug 2018, 09:34

Hi, I'm new to automating Chrome with Autohotkey. If I run this script (see below), I get the error "Websocket.ahk cannot be opened"

Anybody able to assist me?

Code: [Select all] [Expand]GeSHi © Codebox Plus

Attachments
2018-08-24_16-34-05.png
(79.1 KiB) Not downloaded yet

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by Koiu » 07 Aug 2018, 12:04

How to wait until all elements visible?

I try everything but i dont know how to make my script wait until all elements visible
- I try "PageInst.Evaluate("document.readyState")" to make sure the state page is " Complete" but the button still loading
- i try " PageInst.WaitForLoad()" and the button still loading

i really appreciate if anyone can help me. Thanks

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by ocnuybear » 30 Jul 2018, 04:44

Can Chrome.ahk be compiled into a stand alone DLL & called from 3rd party software?

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by GeekDude » 28 Jul 2018, 22:32

teadrinker

https://github.com/G33kDude/Chrome.ahk/ ... 2ef9258164

The fix has been applied and will be present in the next release.




Everyone else

I've seen your posts but haven't yet gotten to replying. I'll get there eventually, please be patient :thumbup:.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by teadrinker » 28 Jul 2018, 22:24

GeekDude, there is a misprint in Chrome.ahk v1.2.
GeekDude wrote:

Code: [Select all]GeSHi © Codebox Plus

		if (ChromePath == "")
RegRead, ChromePath, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Pahs\chrome.exe

App Pahs — App Paths

KusochekDobra wrote:I tried to add to my code processing event "OnExit" ... it turned out that exit from program is unreachable.
I have the same issue on my Win 7 64 AHK 64.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by Manuf » 26 Jul 2018, 04:19

May i ask how to check if a webpage load error? i mean the web page loaded completely but error. I just want to know how to check if it happends. Thanks

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by KusochekDobra » 22 Jul 2018, 05:45

Also noticed that adding a function call by event "Close" terminates the script earlier than the script itself describes. Sometimes the code finishes correctly, but more often it is incorrect:

Code: [Select all] [Expand]GeSHi © Codebox Plus


Maybe I just do not apply my knowledge well. Could you help me with this, or would it be more efficient to track targetDestroyed, instead of adding a function?

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by KusochekDobra » 21 Jul 2018, 18:33

Hello!
I tried to add to my code processing event "OnExit" and noticed, that the GUI is freeze after close a browser window. After that, I added messages on "OutputDebug" and it turned out that exit from program is unreachable. Could you check this effect on your system?

Code: [Select all] [Expand]GeSHi © Codebox Plus

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by Manuf » 09 Jul 2018, 04:23

To @Geekdude

Thanks for your answer. May you help me with this code?

Code: [Select all] [Expand]GeSHi © Codebox Plus



I want to get the x coordinate value of a button but after i run the javascript function ( it works ), i cant assign it to a variable. How can i get the "x = react.left" value in autohotkey ?

Thanks you so much

p.s: Sorry if i cant say it clearly. If anyone know the answer, pls tell me. Thanks

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by bmilcs » 02 Jul 2018, 18:14

And as I wear out my welcome here, I think I've found a bug of some type. After I make a dozen or so DOM JS calls, AHK locks up and this is what I'm seeing for output:

Code: [Select all] [Expand]GeSHi © Codebox Plus



Those are the last lines every single time it locks up. I've tried running the same getelementby syntax, which I know works for a fact, several times and it locks up at the same point every time.

;-----------------------------------------------------------------------------------------------------------------------------

EDIT: SOLVED.

Code: [Select all]GeSHi © Codebox Plus

PageInst.Disconnect()


After hours of tinkering with the code and browsing the Chrome DevTools page, I stumbled upon Page.Disconnect(). Apparently, the connection with Chrome was hitting the max allotment of time or only allows for X amount of actions per connection.

I added this to the end of the cycle of actions that I perform. This has completely fixed all issues I was having in regards to AHK freezing up after X amount of lines or time passed.

Hopefully this helps someone <3

The syntax

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by bmilcs » 02 Jul 2018, 14:15

Sorry if my questions are simplistic once again. I am brand new to DOM and slowly grasping the core concepts.


If CurUrl not contains http://www.amazon.com
ChromeGoUrl("https://www.amazon.com/Punch-Out-Nintendo-Selects-Wii/dp/B005EIIBKY/ref=sr_1_1?s=hi&ie=UTF8&qid=1530544404&sr=8-1&keywords=punchout+nintendo")
PageInst.WaitForLoad()
xx := PageInst.Evaluate("document.getElementById('priceblock_ourprice')[0].innerText")

Image

I cannot figure out why this is giving me an error. Within priceblock-ourprice, there are childnodes which I tried grabbing individually using:

document.getElementById('priceblock_ourprice).childNodes[0].innerText
document.getElementById('priceblock_ourprice).childNode[0].innerText

No luck.

Web site source: https://www.amazon.com/Punch-Out-Ninten ... t+nintendo

Thank you all again! You've helped me tremendously!

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by bmilcs » 01 Jul 2018, 17:58

Here's a fun question for you:

Image

Image

Now, I've figured out that...

PageInst.Evaluate("document.getElementsByTagName('INPUT')[2].value = ' HOUR HERE '")
PageInst.Evaluate("document.getElementsByTagName('INPUT')[4].value = ' MIN HERE '")

So, I am able to populate the hour and minutes field. However, I am baffled as to how to alter the Listbox's value, and set AM or PM.

#1: How do I set the AM PM value in the above Listbox?

;-----------------------------------------------------------------------------------------------------------------------------

ANDDD #2:

Image

Image

#2 How do I apply a check in a checkbox?

#3 Lastly, how can I identify an Element by an aria-label, or other non-standard classification? IE: Not TagName, ID, etc.

IE: Set the value of a field, finding it via "aria-label"

BIG THANKS TO G33KDUDEBROMAN. This sh** is BIG TIME.

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by GeekDude » 25 Jun 2018, 11:06

Manuf

Manuf wrote:Hi sirs. Can you help me with this simple task

i want to write a script to detect
- can check if webpage full loaded
- can check if webpage loaded error
- can check if an element display after an action. Ie: after upload a file, a button will turn from gray to yellow. i want to check that state of the button.

Thanks you

I'm sorry but I can't help with this without a much more thorough understanding of your situation and your goals. I don't have the time to dive that deeply into it right now.

You should be able to check the page readiness state by running PageInst.Evaluate("document.readyState"), which should return how loaded the page is. For the rest of your post I'm not sure.




bmilcs

bmilcs wrote:I have a few questions for you regarding this script:

#1) PageInst.Call("Page.navigate", {"url": address})

I am trying to pass text that isn't a specific URL, but text that I would normally type to search google for. However, I'm receiving errors from Chrome.AHK. Is there a section of the Chrome.ahk script I can edit to allow for non-url text to be passed as valid?

I don't think you can do that directly, but a viable alternative may be to generate a google search url and navigate to that. For example,

Code: [Select all]GeSHi © Codebox Plus

PageInst.Call("Page.navigate", {"url": "https://google.com/search?q=" UriEncode("Search Terms")})

; Modified by GeekDude from http://goo.gl/0a0iJq
UriEncode(Uri, RE="[0-9A-Za-z]") {
VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0), StrPut(Uri, &Var, "UTF-8")
While Code := NumGet(Var, A_Index - 1, "UChar")
Res .= (Chr:=Chr(Code)) ~= RE ? Chr : Format("%{:02X}", Code)
Return, Res
}




bmilcs wrote:#2) How do I retrieve the current URL of the active PageInst?

Try PageInst.Evaluate("window.location.href")



bmilcs wrote:#3) I am a dummy, but are there commands that work with Chrome.ahk that aren't mentioned as examples?
I have zero experience with this, and am wondering if there is another resource detailing the COMS available to us via Chrome.ahk?
In other words, does this just unlock the ability to use Chrome and not give you a full scope of possibilities?

As mentioned at the top of the original post, the Chrome DevTools Protocol's documentation lists a lot of endpoints that you can use from PageInst.Call: https://chromedevtools.github.io/devtools-protocol/



bmilcs wrote:I'm dying to learn more but feel like I'm missing something. Thanks!

Edit: Apologies if I misused vocab or sound like a moron. I've been able to successfully scrape metadata off of websites which is quite exciting! Thank you again for posting such a tremendously useful script!

No need to apologize. I love when people are eager to learn :) . Good luck with your code!

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by bmilcs » 25 Jun 2018, 10:47

I have a few questions for you regarding this script:

#1) PageInst.Call("Page.navigate", {"url": address})

I am trying to pass text that isn't a specific URL, but text that I would normally type to search google for. However, I'm receiving errors from Chrome.AHK. Is there a section of the Chrome.ahk script I can edit to allow for non-url text to be passed as valid?

#2) How do I retrieve the current URL of the active PageInst?

#3) I am a dummy, but are there commands that work with Chrome.ahk that aren't mentioned as examples?
I have zero experience with this, and am wondering if there is another resource detailing the COMS available to us via Chrome.ahk?
In other words, does this just unlock the ability to use Chrome and not give you a full scope of possibilities?

I'm dying to learn more but feel like I'm missing something. Thanks!

Edit: Apologies if I misused vocab or sound like a moron. I've been able to successfully scrape metadata off of websites which is quite exciting! Thank you again for posting such a tremendously useful script!

Re: [Library] Chrome.ahk - Automate Google Chrome using native AutoHotkey. No Selenium!

Post by Manuf » 22 Jun 2018, 02:49

Hi sirs. Can you help me with this simple task

i want to write a script to detect
- can check if webpage full loaded
- can check if webpage loaded error
- can check if an element display after an action. Ie: after upload a file, a button will turn from gray to yellow. i want to check that state of the button.

Thanks you

Top