Hey guys, I’m brand new to this (started today) and I have a problem I can’t find a solution for.
I just need to know if there is a command that will let me locate an element on a webpage in IE, and button in this case, by its ID and click on it.
Is there a command someone can give me and explain to me where I can just plug in the ID of “61” and get the result I want?
Click Elements by ID Topic is solved
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
What browser you're using? Best chance if it's IE bc AHK offers its ComObj-command set to trigger things. Good luck
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
Yes I’m using IE
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
Like I said in the original post, I'm using IE. I know that ComObj can do what im looking for, but i just need that one command right now and dont have time to learn the whole thing yet.
Re: Click Elements by ID
Hope this helps
Code: Select all
pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := true
pwb.Navigate("https://autohotkey.com/boards/")
while pwb.busy or pwb.ReadyState !=4
sleep, 10
pwb.document.getElementById("keywords").value := "Example" ; By ID
pwb.document.getElementsByClassName("button icon-button search-icon").item(0).click() ; By class name (Click)
while pwb.busy or pwb.ReadyState !=4
sleep, 10
MsgBox, The process was successful
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
Thats very helpful, but how can I make it click on a button on a page? What would it look like if I needed it to find a button with an ID of 61, then have it activate that button?
Re: Click Elements by ID
HIAC showed you two alternatives for identifying items. You just need to apply the click() to the one you're interested in:
pwb.document.getElementById("61").click()
pwb.document.getElementById("61").click()
Re: Click Elements by ID
Are you sure that ID is "61"? I doubt it, it may be Index number.. however, try this.
Code: Select all
pwb.document.getElementById("61").click()
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
I'm fairly sure that 61 is its ID, according to when i inspect the element. It still wont click the button. Does Microsoft Edge vs. Internet Explorer matter at all? Is there a way for me to just highlight the button (like what happens when you press TAB) and just have AHK use the {Enter} input instead?
Re: Click Elements by ID
Can you show us that webpage?
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
In this example, the ID is 54, so how would i activate it with AHK? Should I be using Internet Explorer instead of Microsoft Edge?
- Attachments
-
- Screenshot (2).png (160.37 KiB) Viewed 10946 times
Re: Click Elements by ID
Yes, you should be using IE.
And, instead of Goto, use Loop.
And, instead of Goto, use Loop.
Code: Select all
#SingleInstance, Force
OnExit, ExitSub
pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := true
pwb.Navigate("MyWebPage")
while pwb.busy or pwb.ReadyState !=4
sleep, 10
Loop,
{
pwb.document.getElementById("54").click()
while pwb.busy or pwb.ReadyState !=4
sleep, 10
}
return
ExitSub:
pwb.quit()
return
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
How would i modify that to make it click the button 5 times before starting again? Is there a way to make it navigate to a webpage but open up a private browser? How do I make it wait until the webpage is loaded? Thank you very much for your help so far, I appreciate it, please try to answer these three questions in one post if you can
Re: Click Elements by ID
Your screenshot shows that you didn't include any of the rest of what was showed to you to set up the Internet Explorer object. You just put the click line in there. It doesn't work that way. You were given a whole script for a reason. The script HIAC showed also includes the part that waits for the website to load. This is why you really can't do this if you're looking for a single command like you said in your first post. You have to learn and implement the whole approach.
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
Ok, good to know. I figured out a different way around finding the element by its ID. However,
while pwb.busy or pwb.ReadyState !=4
sleep, 10
Are these the lines that cause it to wait?
while pwb.busy or pwb.ReadyState !=4
sleep, 10
Are these the lines that cause it to wait?
Re: Click Elements by ID
Yes, that's correct, but it won't work if you don't set up the object.
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
Ok, gotcha. You mean opening up the webpage with:
pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := true
pwb.Navigate("MyWebPage")
when you say "setting up the object", right? What if i have a different way of getting to the webpage?
pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := true
pwb.Navigate("MyWebPage")
when you say "setting up the object", right? What if i have a different way of getting to the webpage?
Re: Click Elements by ID Topic is solved
Yes, like that. You need to use that method.
-
- Posts: 10
- Joined: 01 Dec 2017, 23:34
Re: Click Elements by ID
Ok. thank you, I got it to work. Thank you both for your help.
Re: Click Elements by ID
I've got a question, and I might be able to read this in the documentation, but I'm assuming that pwb is just a variable name? Or is it a standard naming convention needed for creating and object?
And
pwb := ComObjectCreate("InternetExplorer.Application") takes Internet Explorer and places it into a manageable object to be manipulated more simply in AHK?
And
pwb := ComObjectCreate("InternetExplorer.Application") takes Internet Explorer and places it into a manageable object to be manipulated more simply in AHK?