Automate Chrome fillin edit boxes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Automate Chrome fillin edit boxes

09 Sep 2019, 07:24

Hi Community :wave:

Using below and getElementsByID I am able to fill in edit boxes, but to my surprise the ID is always changing.
Could you please help me with automating the filling of the edit boxes inside chrome.

Code: Select all

<div class="BoxLayout---box_body">
<div class="ContentLayout---content_layout ContentLayout---padding_less">
<div class="FieldLayout---field_layout appian-context-last-in-list">
<div class="FieldLayout---accessibilityhidden"><label class="FieldLayout---field_label" for="66fe0286b46ae2658ea2a935f72fb0ee"></label></div>
<div class="FieldLayout---input_below">
<div><input id="66fe0286b46ae2658ea2a935f72fb0ee" type="text" class="TextInput---text TextInput---align_start" aria-labelledby="66fe0286b46ae2658ea2a935f72fb0ee" placeholder="" value=""></div></div></div></div></div>



<div class="BoxLayout---box_body">
<div class="ContentLayout---content_layout ContentLayout---padding_less">
<div class="FieldLayout---field_layout appian-context-last-in-list">
<div class="FieldLayout---accessibilityhidden"><label class="FieldLayout---field_label" for="65b309ab5f12747a374869e382de4ace"></label></div>
<div class="FieldLayout---input_below">
<div><input id="65b309ab5f12747a374869e382de4ace" type="text" class="TextInput---text TextInput---align_start" aria-labelledby="65b309ab5f12747a374869e382de4ace" placeholder="" value=""></div></div></div></div></div></div></div></div></div>

Code: Select all

F2::
js := "void(document.getElementsByID('479511c552626f98c6c2fa346efa7aef').value='123456)"
ChromeRunJs(js)
Return

;__________________________________________________________________________________________________________________

ChromeRunJs(ByRef js) {
	static addrBar
	if !addrBar || !WinExist("ahk_id " addrBar.hWnd) {
		if !addrBar := FindAddressBar() {
			throw "FindAddressBar failed."
		}
	}

	addrBar.accObj.accValue(0) := "	" . js
	addrBar.accObj.accSelect(0x1, 0)
	ControlSend,, {Enter}
	Sleep 100
}

FindAddressBar(WinTitle := "ahk_exe chrome.exe", oAcc := "", accPath := "") {
	if !oAcc {
		if hWnd := WinExist(WinTitle) {
			oAcc := Acc_ObjectFromWindow(hWnd)
			while oAcc.accRole(0) != 9 { ; ROLE_SYSTEM_WINDOW := 9
				oAcc := Acc_Parent(oAcc)
			}
		} else {
			throw WinTitle " not found."
		}
		
	}

	for i, child in Acc_Children(oAcc) {
		nRole := child.accRole(0)
		
		if (nRole = 42) { ; ROLE_SYSTEM_TEXT := 42
			if (child.accName(0) ~= "i)address|地址") {
				accPath := LTrim(accPath "." i, ".")
				return {accObj: child, accPath: accPath, hWnd: hWnd}
			}
		}

		/*
			ROLE_SYSTEM_APPLICATION := 14
			ROLE_SYSTEM_PANE        := 16
			ROLE_SYSTEM_GROUPING    := 20
			ROLE_SYSTEM_TOOLBAR     := 22
			ROLE_SYSTEM_COMBOBOX    := 46
		*/
		static oGroup := {14:1, 16:1, 20:1, 22:1, 46:1}
		if oGroup.HasKey(nRole) {
			if result := FindAddressBar(, child, accPath "." i) {
				return result
			}
		}
	}
}

#Include, Acc.ahk
Getfree
Posts: 231
Joined: 12 Oct 2014, 18:00

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 08:57

Try with:
js := "void(document.querySelector('div[class*=input_below] input[id][type=text][class*=TextInput]').value='123456')"
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 09:40

Getfree wrote:
09 Sep 2019, 08:57
Try with:
js := "void(document.querySelector('div[class*=input_below] input[id][type=text][class*=TextInput]').value='123456')"
Thank you Getfree, I am novice, could you please help me
using above html data
show me what exactly should be my js query.
Thank you in advance.
Getfree
Posts: 231
Joined: 12 Oct 2014, 18:00

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 10:21

I'm not sure what you mean by JS query.
The line of code I've just given you is the JS code you have to inject from your AHK script.

You have to use that line instead of this one:
js := "void(document.getElementsByID('479511c552626f98c6c2fa346efa7aef').value='123456)"
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 10:30

this Document.getElementsByID (479511c552626f98c6c2fa346efa7aef) is not constant, is always changing.
is there any other way I can fill these edit boxes ?
Getfree
Posts: 231
Joined: 12 Oct 2014, 18:00

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 10:34

Yes, there is.
Did you use the line of code I suggested?
That should fill the text box even if its ID changes.
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 10:40

Getfree wrote:
09 Sep 2019, 10:34
Yes, there is.
Did you use the line of code I suggested?
That should fill the text box even if its ID changes.
Yes I tried, but if the id is same then only it is able to fill in the edit boxes, and this
id="66fe0286b46ae2658ea2a935f72fb0ee"
is always changing.

<input id="66fe0286b46ae2658ea2a935f72fb0ee" type="text" class="TextInput---text TextInput---align_start" aria-labelledby="66fe0286b46ae2658ea2a935f72fb0ee" placeholder="" value="">
Getfree
Posts: 231
Joined: 12 Oct 2014, 18:00

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 10:57

Yes, but the code I gave you doesn't use the ID, so it doesn't matter if it keeps changing.
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 11:04

Getfree wrote:
09 Sep 2019, 10:57
Yes, but the code I gave you doesn't use the ID, so it doesn't matter if it keeps changing.
<div><input id="66fe0286b46ae2658ea2a935f72fb0ee" type="text" class="TextInput---text TextInput---align_start" aria-labelledby="66fe0286b46ae2658ea2a935f72fb0ee" placeholder="" value=""></div></div></div></div></div>

js := "void(document.getElementsByID('66fe0286b46ae2658ea2a935f72fb0ee').value='123456')"

Do you mean to say, 66fe0286b46ae2658ea2a935f72fb0ee if this gets changed also, we can fill in the edit box ?
I am not able to, could you please elaborate more, Thank you
Getfree
Posts: 231
Joined: 12 Oct 2014, 18:00

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 11:07

That's not the line of code I gave you.

This is it:
js := "void(document.querySelector('div[class*=input_below] input[id][type=text][class*=TextInput]').value='123456')"
ahklearner
Posts: 313
Joined: 23 Jan 2015, 01:49

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 11:42

Getfree wrote:
09 Sep 2019, 11:07
That's not the line of code I gave you.

This is it:
js := "void(document.querySelector('div[class*=input_below] input[id][type=text][class*=TextInput]').value='123456')"
Really sorry, could not understand it at first, its working too good,
one more thing
on that page there are many edit boxes, the constant for each box is its label or title we can say.
How can I fill-in edit box details in accordance to their title, Thank you very much again :)

<div class="BoxLayout---box_heading" role="heading" aria-level="2" title="Name">Name</div>

<div class="BoxLayout---box_heading" role="heading" aria-level="2" title="Role">Role</div>

Code: Select all

<div class="BoxLayout---box BoxLayout---info BoxLayout---margin_below_none">
<div class="BoxLayout---box_heading_wrapper">
<div class="BoxLayout---box_heading" role="heading" aria-level="2" title="Process Name">Process Name</div></div>
<div aria-hidden="false" class="rah-static rah-static--height-auto" style="height: auto !important; overflow: visible !important;">
<div>
<div class="BoxLayout---box_body">
<div class="ContentLayout---content_layout ContentLayout---padding_less">
<div class="FieldLayout---field_layout appian-context-last-in-list">
<div class="FieldLayout---accessibilityhidden"><label class="FieldLayout---field_label" for="66fe0286b46ae2658ea2a935f72fb0ee"></label></div>
<div class="FieldLayout---input_below">
<div><input id="66fe0286b46ae2658ea2a935f72fb0ee" type="text" class="TextInput---text TextInput---align_start" aria-labelledby="66fe0286b46ae2658ea2a935f72fb0ee" placeholder="" value="123456"></div></div></div></div></div></div></div></div>



<div class="ColumnLayout---column ColumnLayout---align_start ColumnLayout---top appian-context-last-in-list" data-padding-left="0" data-padding-right="-20">
<div class="BoxLayout---box BoxLayout---info BoxLayout---margin_below_none">
<div class="BoxLayout---box_heading_wrapper">
<div class="BoxLayout---box_heading" role="heading" aria-level="2" title="Role">Role</div></div>
<div aria-hidden="false" class="rah-static rah-static--height-auto" style="height: auto !important; overflow: visible !important;">
<div>
<div class="BoxLayout---box_body">
<div class="ContentLayout---content_layout ContentLayout---padding_less">
<div class="FieldLayout---field_layout appian-context-last-in-list">
<div class="FieldLayout---accessibilityhidden"><label class="FieldLayout---field_label" for="70a8a92cca70f1f3ee806540ad9371e9"></label></div>
<div class="FieldLayout---input_below">
<div><input id="70a8a92cca70f1f3ee806540ad9371e9" type="text" class="TextInput---text TextInput---align_start" aria-labelledby="70a8a92cca70f1f3ee806540ad9371e9" placeholder="" value=""></div></div></div></div></div></div></div></div></div>
Getfree
Posts: 231
Joined: 12 Oct 2014, 18:00

Re: Automate Chrome fillin edit boxes

09 Sep 2019, 12:23

This might work (untested).
js := "void(document.querySelector('[role=heading][title=Role]').closest('.BoxLayout---info').querySelector('input[id][type=text]').value='123456')"

Change the part in red with the desired title.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Hugh Jars, Mateusz53, MrDoge, peter_ahk and 367 guests