Cannot click an html button without name or id tag

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dsainato
Posts: 3
Joined: 19 Apr 2018, 13:25

Cannot click an html button without name or id tag

19 Apr 2018, 14:34

I am trying to click a button using DOM on an HTML form where the button has neither an ID nor a name tag. I have tried various methods like document.getElementByID, document.getElementsByName, document.getElementsByTagName, using x and y coordinates, etc. Nothing seems to work. Other buttons with names or an ID are no problem. Any help would be greatly appreciated. The HTML code that I am interrogating looks like this :

<tr>
<td align="center">
<a href="UserIDCtlr?action=get&USERID=xxxx">&nbsp;SELECT&nbsp;</a></td>
<td align="left"> xxxx</td>
<td align="left">smith</td>
<td align="left">john</td>
<td align="left">ATTP </td>
</tr>

The button I am trying to click is the hyperlink (href=) above. All other buttons and elements are not an issue.

Any help would be greatly appreciated.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Cannot click an html button without name or id tag

19 Apr 2018, 16:50

<a> is the tag for links.
getElementsByTagName
Example:

Code: Select all

document.getElementsByTagName("a")[0]
or
querySelector
Example:

Code: Select all

document.querySelector("body > a")
HTH
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: Cannot click an html button without name or id tag

19 Apr 2018, 17:03

maybe it is within a frame?
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
dsainato
Posts: 3
Joined: 19 Apr 2018, 13:25

Re: Cannot click an html button without name or id tag

20 Apr 2018, 08:58

Xtra and tank, thank you for the help. It's not in a frame. I had tried the getElementsByTagName earlier and I also gave the document.querySelector a try but neither seem to work. I did find this bit of code in a blog and included it in my script to identify the occurrence of <td> that I could possibly try to use:

Msgbox, About to Hit the Select Button process

cells := ExpSecSession.document.getElementsByTagName("td")
loop % cells.length
{
text := cells[ A_Index-1 ].innerText
if text <>
MsgBox % "td (" A_Index-1 ")`n" text
}

Then I tried this code:
ExpSecSession.document.getElementsByTagName( "td")[11].focus().Click()

But that still didn't do the trick. I'll keep digging.
dsainato
Posts: 3
Joined: 19 Apr 2018, 13:25

Re: Cannot click an html button without name or id tag

20 Apr 2018, 13:20

Problem Solved! I found the following code on a post and incorporated into my script, and it worked!!!


divs := ExpSecSession.document.getElementsByTagName("tr")

loop % divs.length
{
innerText := divs[A_Index-1].innerText
If instr(innerText, "SELECT")
{
divs[A_Index-1].getElementsByTagName("a")[0].click()
break
}
}

Thanks for the help all

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer and 267 guests