Click Elements by ID Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Re: Click Elements by ID

07 Feb 2018, 18:27

I guess another question, where do I find the library to add methods to the object... i.e.

pwb.visible
pwb.navigate

where did you find these methods?
gregster
Posts: 9111
Joined: 30 Sep 2013, 06:48

Re: Click Elements by ID

07 Feb 2018, 18:49

Yes, pwb is just a arbitrary variable name, you could choose any valid variable name instead.

And yes, ComObjectCreate("InternetExplorer.Application") creates an Internet Explorer COM object with a standardized interface for automation. The COM interface is something Internet Explorer provides (other web browsers don't have it, but MS Office, Acrobat Reader, foobar etc. offer similar interfaces) and generally can be accessed via most programming languages.

Methods, properties etc. are exposed by the COM object. That has nothing to do with AHK itself. In general, you should be able to find it in the docs of the program you are interfacing, if the program is offering it. Probably this for IE: https://msdn.microsoft.com/en-us/librar ... s.85).aspx and you can find many examples here in the forum and the internet...
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: Click Elements by ID

07 Feb 2018, 19:34

Yes, pwb is just a variable name for the object. I believe it stands for pointer to the web browser. I see a lot of people using just wb for web browser.

I guess I would ask you what you mean by a more manageable object. More manageable than what? More manageable than a browser that doesn't have that interface, I guess is true. It's the object that is provided by IE as an API (Application Programming Interface) for the HTML document that is known as the DOM (Document Object Model). It is available for any language that wishes to use it, not just AHK. I'm no expert, so maybe my terminology isn't exactly correct, but that's the gist of it.

Edit: I didn't see gregster's post even though mine came later (didn't see page 2 of the thread yet). He explained it well.
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Re: Click Elements by ID

08 Feb 2018, 11:44

yeah, boiler, I mean manageable as in be able to interact with it as an object. But thanks everyone!
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Re: Click Elements by ID

08 Feb 2018, 15:09

I've copied the code that HIAC posted earlier in this thread and I'm receiving an error; Error: 0x80004005 - Unspecified error

I'm attempting to launch to a site in IE, click a copy button that copies a password to my clipboard, and then return it in a MsgBox as a proof of concept. Again, I'm relatively new to AHK, and programming in general.

Code: Select all

^!n::
   	pwb := ComObjCreate("InternetExplorer.Application")
	pwb.Visible := true
	pwb.Navigate("valid URL?")
	Example := pwb.document.getElementById("validID").click() 
	MsgBox, "%Example%"
Return
Now, I get this error long before I attempted to modify anything that HIAC posted. But it is a pretty lengthy error that appears in a msgbox, whether I want it to are not.

Error: 0x80004005 - Unspecified error
Source: (null)
Description: (null)
HelpFile: (null)
HelpContext: 0

Specifically: document
Line#
001: Return
002: pwb := ComObjtCreate("InternetExplorer.Application")
003: pwb.Visible := true
004: pwb.Navigate("http://source URL")
----> 007: Example := pwb.document.getElementById("I have the valid element ID").click() (I'm assuming this may be a problem because I'm only passing the .click() function to the DOM when I want the VALUE(password) of what the .click() function should be collecting)
011: MsgBox, "%Example%"
012: Return
013: Exit
014: Exit
014: Exit

Continue running the script?
Last edited by rynsp8 on 12 Feb 2018, 12:46, edited 1 time in total.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Click Elements by ID

08 Feb 2018, 15:15

You need to wait for the page to load before interacting with it

As a test you Can use sleep or one of the other wait methods show
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Re: Click Elements by ID

08 Feb 2018, 15:30

Good test Blackholyman... so, I added

Code: Select all

^!n::
    pwb := ComObjCreate("InternetExplorer.Application")
	pwb.Visible := true
	pwb.Navigate("valid URL?")
	
	Sleep, 10000
	
	Example := pwb.document.getElementById("copyLink_13965").click() ; By ID
	MsgBox, "%Example%"
Return
and I get a new code, Error: 0x800706B5 - The interface is unknown. So, I'm assuming that the "---->" arrow is pointing to the line that is causing the issue? Because it is pointing to the variable I'm trying to create, "Example".
Last edited by rynsp8 on 12 Feb 2018, 12:46, edited 1 time in total.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Click Elements by ID

08 Feb 2018, 16:44

Try this

Code: Select all

Sleep, 10000
	clipboard := "" ; empty clipboard for clipwait to work
	wb.document.getElementById("copyLink_13965").click() ; By ID
        Clipwait, 1
	MsgBox, %clipboard%
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Re: Click Elements by ID

08 Feb 2018, 18:03

Still getting Error: 0X800706B5 - The Interface is unknown... I should mention that the button I'm attempting to interact with already copies the password to the clipboard.

It seems logically that I should be able to send a .click() command to that specific button, and the clipboard should already contain the password value.
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Click Elements by ID

08 Feb 2018, 18:08

It May simply not be a butten element Can you post the html of you button or page with the button
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
rynsp8
Posts: 46
Joined: 30 Jan 2018, 12:45

Re: Click Elements by ID

09 Feb 2018, 09:16

funny enough, it's an anchor element...

Code: Select all

<tr>
    <td style="vertical-align: top; white-space: nowrap;">
        <a title="Copy to Clipboard." class="copyhyperlink fa fa-clipboard" id="copyLink_13965" sytle="cursor: pointer;" onclick="getSecretViewDrawer().copyClipboard(13965,true);">Copy to Clipboard.</a>
    </td>
</tr>
perhaps I can attempt to capture the onclick method?
User avatar
tankuser
Posts: 26
Joined: 29 Sep 2013, 16:04

Re: Click Elements by ID

09 Feb 2018, 11:28

pwb is common on this forum from when we used to all use Seans COM Library and the objects werent objects but pointers. It literally stood for pointer web browser.
but yes pwb is just a variable name and nothing special

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, Google [Bot] and 199 guests