Accessing Web Elements Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aromero
Posts: 51
Joined: 01 Aug 2016, 11:53

Accessing Web Elements

24 May 2018, 17:12

I am using an AHK script to fill out a web page form but am having a problem accessing some of the elements. The page has 3 input boxes https://drive.google.com/open?id=1-RxUU ... jDvzjaTC2V. The HTML for these elements is https://drive.google.com/open?id=1OMeTx ... XNVtaZ4TUc.

I need to set the first input box to User ID, second input box to Is, and the third input box to user12345. I am attempting to use getElementsByClassName for the first time. I have been able to access the other elements by getElementById but since these ones don't have an ID, I'm at a loss. Below is what I have tried. So what is the trick to accessing these web elements?

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;Create an Internet Explor instance.
wb := ComObjCreate("{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}") ; create a InternetExplorer Medium instance
wb.Visible := True

wb.Navigate("https://zzzmyWebPage/Users")
While wb.busy ; wait for the page to load
   Sleep, 2000

wb.document.getElementById("search").value := "testing" ;works
wb.document.getElementByID("toggleAdvancedSearch").click()  ;works

wb.document.getElementsByClassName("advancedSearchField")(0).value = "UserID"
wb.document.getElementsByClassName("advancedSearchOperator")(0).value = "Is"
wb.document.getElementsByClassName("advancedSearchOperand")(0).value = "user12345"

Sleep, 5000

msgbox Done!
Sleep, 10000
wb.quit()
return
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Accessing Web Elements

24 May 2018, 18:31

I think you have a misunderstanding of syntax. Maybe I'am on the wrong way but you assign a value to a syntax that I never see befor: (0).value = "UserID". Theres a space between to forgoing function and the alien syntax you use. The function wb.document.getElementsByClass.... Missing a connection to (0).value. And the second syntax error is not to use := to assign a value bordered with two ". This can't work.
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Accessing Web Elements

24 May 2018, 18:33

I think you have a misunderstanding of syntax. Maybe I'am on the wrong way but you use to assign a value with a syntax that I've never see befor: (0).value = "UserID". There is a space between the forgoing function and the alien syntax you use. The function wb.document.getElementsByClass.... Missing a connection to (0).value. And the second syntax error is not to use := to assign a value bordered with two ". This can't work.
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Accessing Web Elements  Topic is solved

25 May 2018, 01:02

the correct syntax is getElementsByClassName("some_class_name")[0] ..... (0) will through error

Code: Select all

wb.document.getElementsByClassName("advancedSearchField")[0].value = "UserID"
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory
aromero
Posts: 51
Joined: 01 Aug 2016, 11:53

Re: Accessing Web Elements

25 May 2018, 10:39

Thanks Xeo786, I tried your code and it almost worked. I still had to use := instead of = to set the value of the field to user id.

Code: Select all

wb.document.getElementsByClassName("advancedSearchOperand")[0].value := "user id" ;works
wb.document.getElementsByClassName("advancedSearchOperand")[0].value = "user id" ;doesn't work
User avatar
Xeo786
Posts: 759
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Accessing Web Elements

26 May 2018, 00:39

"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AHK_user, sharonhuston and 223 guests