How can I send values to a text field, with Chrome.ahk
for Example gmail:
Code: Select all
mail := "[email protected]"
PageInstance.Evaluate("document.querySelector('#identifierId')").value="%mail%"
Code: Select all
mail := "[email protected]"
PageInstance.Evaluate("document.querySelector('#identifierId')").value="%mail%"
Code: Select all
var := "Test"
PageInst.Evaluate("document.querySelector('input[name=keywords]').value = '" var "' ")
Code: Select all
var := "[email protected]"
PageInst.Evaluate("document.querySelector('input[name=identifier]').value = '" var "' ")
Code: Select all
PageInstance.Evaluate("document.getElementsByClassName(" RveJvd snByac ")[0].click")
Code: Select all
PageInstance.Evaluate("document.getElementsByClassName('RveJvd snByac')[0].click()")
gregster wrote: ↑05 Mar 2019, 23:53This is a javascript way of doing it - with Chrome.ahk you could also navigate through the node structure, determine coordinates for the button and use the Input.dispatchMouseEvent method instead. That is an alternative, if the click() method doesn't work for some reason (seems to happen on some websites).
Not yet on the forum, I think. It's use with AHK is still relatively new compared to IE COM. But here is some example usage pulled from my experiments with Chrome.ahk (I plan to post some helper functions for the library in the near future). Btw, there are more options available via https://chromedevtools.github.io/devtools-protocol/tot/Input
Code: Select all
;[...] Initialize your Chrome instance first
; Navigate to the desired URL
url := "https://www.autohotkey.com/"
PageInst.Call("Page.navigate", {"url": url})
PageInst.WaitForLoad()
sleep 500
; Determine x, y, w(idth), h(eight) of button to click
attribute := "mbr-buttons__btn btn btn-lg animated fadeInUp delay btn-success" ; class of the desired button
index := 1
objPos := Chrm_GetPosition(PageInst, "Class", attribute, index)
; Determine center of button and send click to Chrome browser
Chrm_ClickCenter(PageInst, objPos , "left", 1, 100)
;[...] Close your Chrome instance
return
Esc::ExitApp
; helper functions ------------------------------------------------
Chrm_ClickCenter(PageInst, Pos ,button := "left", count :=1, delay := 100){
x := Pos.x + Pos.w/2, y := Pos.y + Pos.h/2
PageInst.Call("Input.dispatchMouseEvent" , {"type" : "mousePressed", "x" : x , "y" : y, "button" : button, "clickCount" : count } )
sleep, delay
PageInst.Call("Input.dispatchMouseEvent" , {"type" : "mouseReleased", "x" : x , "y" : y, "button" : button, "clickCount" : count } )
return
}
Chrm_GetPosition(PageInst, method :="Class" , attribute :="" ,Index := 1){
obj:={}
oMethods := {"class" : "sByClassName", "name" : "sByName" , "tag" : "sByTagName", "id" : "ById"}
if oMethods.HasKey(method)
element := oMethods[method]
else
{
msgbox "Error in Chrm_GetPosition: Unknown method"
return "unkown method"
}
index := (method = "id") ? "" : "[" index-1 "]"
obj.x := PageInst.Evaluate("document.getElement" element "('" Attribute "')" index ".getBoundingClientRect().x").value
obj.y := PageInst.Evaluate("document.getElement" element "('" Attribute "')" index ".getBoundingClientRect().y").value
obj.w := PageInst.Evaluate("document.getElement" element "('" Attribute "')" index ".getBoundingClientRect().width").value
obj.h := PageInst.Evaluate("document.getElement" element "('" Attribute "')" index ".getBoundingClientRect().height").value
return obj
}
Thank you.gregster wrote: ↑17 Mar 2019, 02:43This should click the 'Download' button on the AutoHotkey startpage and take you to the 'Downloads' page https://www.autohotkey.com/download/
I assume click() would work here, too, but I haven't tested it. This is only for demonstration purposes - obviously you could also directly navigate to the page, in this case. Hope this helps!