Assigning the variable of InnerText to constantly changing InnerText to code

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Assigning the variable of InnerText to constantly changing InnerText to code

09 Aug 2018, 09:49

Code: Select all

<label id="formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt167" class="ui-outputlabel ui-widget">Vehicle Query</label>
we send the data via the auto hot key on the internet page where we made the vehicle inquiry.

but there is a constantly changing form id number.

label id = "formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt167"
j_idt167 section changes every day. "j_idt169" or "j_idt180" in the day .... there is a constantly changing code. so every day I have to change the codes manually by logging in ..

can you get the most current version of this code when you load the page from your page?


I want to automatically get the variable we mentioned when loading the page, in the code I use myself. page is loading
"formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt???"
and fetch the most current state in the code.

I can give hope.

Thank you for your help.

note : I have to manually fix the InnerText because it changes continuously throughout the day.
so when the page loads, I want to get the related code innertext and place the corresponding part in my code.

Code: Select all

loaded := false
While !loaded
{
    try
    {
        if (pwb.document.getElementById("formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt167").innertext = "Vehicle Query")
            loaded := true
    }
    Sleep 10
}
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Assigning the variable of InnerText to constantly changing InnerText to code

10 Aug 2018, 08:34

Hi chngrcn,

I'm not sure to fully understand what you're trying to achieve.

Maybe you're trying to get a way to reliably retrieve a specific HTML element, whose id is changing. In this case, if you're lucky, you can do this using getElementByClassName:

Code: Select all

; getElementsByClassName returns an HTMLCollection; you might need to specify a number different from 0 as index
element := pwb.document.getElementsByClassName("ui-outputlabel ui-widget")[0]
Otherwise, for a finer identification, use querySelector:

Code: Select all

; a simple wrapper for the querySelector method
pwb.document.parentwindow.execScript("var _wrapper = {querySelector: function(_selector) { return document.querySelector(_selector); }};")
; ...
element := pwb.document.parentwindow._wrapper.querySelector("label[id^='formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt'].ui-outputlabel.ui-widget")
Hope this helps.
my scripts
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Assigning the variable of InnerText to constantly changing InnerText to code

11 Aug 2018, 09:30

Code: Select all

; a simple wrapper for the querySelector method
pwb.document.parentwindow.execScript("var _wrapper = {querySelector: function(_selector) { return document.querySelector(_selector); }};")
; ...
element := pwb.document.parentwindow._wrapper.querySelector("label[id^='formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt'].ui-outputlabel.ui-widget")

I tried this code but I did not get results. Could you write it in different versions by developing a little bit more of your code .. I guess it's something we caught.
please show this code of your innertext with MsgBox .. please try to write different codes.
thank you so much
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Assigning the variable of InnerText to constantly changing InnerText to code

12 Aug 2018, 04:14

Hi chngrcn,

Code: Select all

#NoEnv
#SingleInstance force
#Warn

HTML =
(
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=edge"><meta charset="utf-8" />
		<title>test</title>
	</head>
	<body>
		<label id="formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt167" class="ui-outputlabel ui-widget">
			Vehicle Query
		</label>
		<label id="formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt168" class="ui-outputlabel ui-widget">
			Vehicle Query 2
		</label>
	</body>
</html>
) ; end of the <continuation section> https://www.autohotkey.com/docs/Scripts.htm#continuation

oHTML := ComObjCreate("HTMLFile") ; create a HTML document object to operate on for testing purpose
oHTML.write(HTML) ; writes the html-formatted to the document stream
oHTML.close()
; let's say your pwb.document will be from now on referred to as oHTML in this code (pwb.document ~= oHTML)

; ===== using getElementsByClassName ===== ; getElementsByClassName method: https://www.w3schools.com/jsref/met_document_getelementsbyclassname.asp
	; getElementsByClassName returns an HTMLCollection; you might need to specify a number different from 0 as index; also, indexes in javascript start with zero:
	element := oHTML.getElementsByClassName("ui-outputlabel ui-widget")[0]
	MsgBox % element.innerText
	element := oHTML.getElementsByClassName("ui-outputlabel ui-widget")[1]
	MsgBox % element.innerText
	
; ===== using querySelector =====	; querySelector method: https://www.w3schools.com/jsref/met_document_queryselector.asp
	oHTML.querySelector("label[id^='formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt'], .ui-outputlabel, .ui-widget")
	MsgBox % element.innerText
	/*
	selector syntax exegesis:
		[attribute^=value] 	label[id^="formId"] 	Selects every <label> element whose id attribute value begins with "formId"
		.class 			.ui-outputlabel		Selects all elements with class="ui-outputlabel"
	see also: https://www.w3schools.com/cssref/css_selectors.asp
	*/
	; ! you might need to use, however, and when using the querySelector method, a simple wrapper for it to ensure it can be used regardless of the documentMode:
	oHTML.parentwindow.execScript("var _wrapper = {querySelector: function(_selector) { return document.querySelector(_selector); }};")
	; see also: is-it-possible-to-execute-a-javascript-function-loaded-in-a-webbrowser-control: https://stackoverflow.com/questions/13612369/is-it-possible-to-execute-a-javascript-function-loaded-in-a-webbrowser-control-a/15172869
	; execute the wrapper function (executing-a-javascript-function-in-activex-control: https://autohotkey.com/board/topic/86711-executing-a-javascript-function-in-activex-control/)
	element := oHTML.parentwindow._wrapper.querySelector("label[id^='formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt'].ui-outputlabel.ui-widget")
	MsgBox % element.innerText
my scripts
chngrcn
Posts: 190
Joined: 29 Feb 2016, 08:55

Re: Assigning the variable of InnerText to constantly changing InnerText to code

13 Aug 2018, 05:30

It works in the html code you have given. but the pwb method I'm implementing (internet explorer) is not working on code.
Can I ask you something like this?
in the html code I have given, how can we display the formId part with MessageBox?
part I need the formID part. constantly changing part formID code.

Code: Select all

<label id="formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt167" class="ui-outputlabel ui-widget">Vehicle Query</label>
I want you to give it with the message when the page is loading.
formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt167
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Assigning the variable of InnerText to constantly changing InnerText to code

13 Aug 2018, 12:12

chngrcn wrote:It works in the html code you have given. but the pwb method I'm implementing (internet explorer) is not working on code.
I see no reason why it should not work using the pwb method..
chngrcn wrote:in the html code I have given, how can we display the formId part with MessageBox?
Once you get the element, use one of the following:

Code: Select all

id := element.id
MsgBox % id
id := element.getAttribute("id")
MsgBox % id
chngrcn wrote:part I need the formID part. constantly changing part formID code.
Maybe:

Code: Select all

; id := element.getAttribute("id")
id := "formId:tescilliAracIslemComponent:tescilliAracIslemAracSorgula:j_idt167"
RegExMatch(id, "\d+$", match) ; retrieve the last digits of the id attribute value
MsgBox % match
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], DevWithCoffee, Google [Bot], Rohwedder, Sarhad and 135 guests