AHK won't recognize Chrome Page Elements?

Get help with using AutoHotkey and its commands and hotkeys
t4akawolf
Posts: 12
Joined: 30 Jul 2016, 03:30

AHK won't recognize Chrome Page Elements?

12 Jun 2019, 09:20

Objective: Create a shortcut to find and click on a button on the page, then focus cursor on the text field that appears.



The Button:
Screenshot (56).png
Screenshot (56).png (48.3 KiB) Viewed 371 times


What happens when I click on the Button:
Screenshot (58).png
Screenshot (58).png (57.79 KiB) Viewed 371 times


Chrome Console view when I right click on the button and Inspect Element; and underneath that after I manually click on the Button, then right click the text field and Inspect Element:
Screenshot (62).png
Screenshot (62).png (260.08 KiB) Viewed 371 times


What I tried:

Code: Select all

!q::
wb.document.getElementById("anId").click()
sleep 1000
wb.document.getElementById("newNote").focus()
return
This was based on this thread that I found.


The shortcut is not finding/clicking the button. I also tried getElementsByName, and removing "wb" from the beginning of the line (because I noticed that in the dev console) but no luck. It's not finding the button. After a while, I gave up on trying to find the button and did this:

Code: Select all

!q::
Click 99 323
Sleep 1000
wb.document.getElementById("newNote").focus()
return
Because the button maintains its position in relation to my screen, despite scrolling through the page up and down. But it's unable to find the text-field either.

Can anyone tell me where I'm going wrong, why it's going wrong, and how to fix it?

[Mod edit: Link fixed]
gregster
Posts: 2658
Joined: 30 Sep 2013, 06:48

Re: AHK won't recognize Chrome Page Elements?

12 Jun 2019, 09:29

It hasn't anything to do with AHK. Generally, Chrome doesn't support the COM interface you are trying to use (Internet explorer, that is used in the example on Stackoverflow, is the only browser that does).

For Chrome you either need to use geekdude's Chrome.ahk library or the Selenium webdriver/chromedriver. Their syntax is somehow similar - you can use the DOM, too.

Chrome.ahk: https://www.autohotkey.com/boards/viewtopic.php?f=6&t=42890
Selenium: https://www.autohotkey.com/boards/viewtopic.php?f=7&t=32323
t4akawolf
Posts: 12
Joined: 30 Jul 2016, 03:30

Re: AHK won't recognize Chrome Page Elements?

12 Jun 2019, 10:05

Thank you so much for your response.

I should have clarified, though, I am a total novice here (apart from a few weeks with AHK a couple of years ago). I checked out the first link but I have absolutely no idea where to even begin.

I would really appreciate if someone could show me what the script should be.

Thank you.
User avatar
eblanc
Posts: 62
Joined: 08 May 2019, 14:41

Re: AHK won't recognize Chrome Page Elements?

12 Jun 2019, 16:58

t4akawolf wrote:
12 Jun 2019, 14:31
Anyone? Please?
Noob here.

Could using mousemove, and mouse click work?

what about using tab for when the screen opens.

you could use getpixel color to check the page is loaded.
rommmcek
Posts: 622
Joined: 15 Aug 2014, 15:18

Re: AHK won't recognize Chrome Page Elements?

14 Jun 2019, 04:44

May be this will give you some idea:

Code: Select all

#Include Chrome.ahk

ChromeInst := new Chrome("ChromeProfile")
PgInst := ChromeInst.GetPage()
PgInst.Call("Page.navigate", {"url": "https://www.autohotkey.com/boards/ucp.php?mode=login"})
PgInst.WaitForLoad()
send, {Tab 3} ; not needed, just for demo

PgInst.Evaluate("document.getElementsByClassName('inputbox autowidth')[0].value='t4akawolf';").Value
PgInst.Evaluate("document.getElementsByClassName('inputbox autowidth')[1].value='PASSWORD';").Value
sleep, 1000 ; not needed, just for demo
PgInst.Evaluate("document.getElementsByClassName('inputbox autowidth')[0].select();") ; not needed, just for demo
sleep, 1000 ; not needed, just for demo
PgInst.Evaluate("document.getElementsByClassName('button1')[0].focus();") ; not needed, just for demo
sleep, 1000 ; not needed, just for demo
PgInst.Evaluate("document.getElementsByClassName('button1')[0].click();")
PgInst.WaitForLoad()

#IfWinActive, ahk_exe chrome.exe
!x:: ; close session
PgInst.Evaluate("document.getElementsByClassName('icon fa-power-off fa-fw')[0].click();")
PgInst.WaitForLoad()
PgInst.Call("Browser.close")
PgInst.Disconnect()
ExitApp
P.s.: Replace word PASSWORD with your real password.

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], hannahelappin, joefiesta, MannyKSoSo, Newbie0919, Odlanir and 158 guests