Com Click on "Button Class"

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chase1
Posts: 18
Joined: 15 Jul 2016, 19:42

Com Click on "Button Class"

21 Sep 2017, 23:11

Hi Everyone.

Have not been able to control a certain website with id or class or name (all things I learned because of every awesome person on these forms!)

Two different codes are below, same problem with both of them:

Code: Select all

<button class="right view-all-orders" ng-click="ordersTableCtrl.viewAllOpenOrders()" translate="fulfillment.overview.ordersTable.buttonLabel.viewAll"><span>View All Open Orders</span></button>
And

Code: Select all

<label for="757648703" translate-attr="{ title: 'fulfillment.selectId' }" translate-values="{ id: deTraCtrl.doc.appkey1 }" title="Select BN8Y5VG">&nbsp;</label>
I think I need to set a "While" and loop through the page until it gets to the part that I want? But I am very shaky on how to do this.
From other posts I've gathered the answer will look something like this:

Code: Select all

While ( value <> "right view-all-orders" )
    value           := Pwb.document.getElementsByTagName( "div")[ A_Index -1].value, index := A_Index -1

Pwb.document.getElementsByTagName( "div")[ index].Click()


(Although this fails when I try to run it)

But my understanding of how this actually works is a more than a little fuzzy.
Any help or links to references that might help would be a HUGE help.

Thanks
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Com Click on "Button Class"

21 Sep 2017, 23:45

I'm a little shaky when it comes to HTML and JS stuff. But in this case, from your example code, you've supplied us with a <button> with class "right view-all-orders". Why are you searching for "div" Tags? I'm pretty sure you want .getElementsByTagName("button"). Now, you may also not want .value, as that might come back blank (not sure what the value of a button necessarily is). Try using .className rather than .value. Play around with the JS in this site:

https://www.w3schools.com/js/js_events.asp -- play the first example. And compare that code with the code I have below, and see how that works for you. Both the original sample code on that site and the example I have below are functional, and I think comparing the two will help you understand what you're looking for.

Code: Select all

<!DOCTYPE html>
<html>
<body>

<button id="button" class="munchies" onclick="document.getElementById('demo').innerHTML=document.getElementById('button').className">The time is?</button>

<p id="demo"></p>

</body>
</html>
Also, it's not a bad idea when diagnosing your AHK code to use MsgBox % value to double check that the right values are populating the variables.
chase1
Posts: 18
Joined: 15 Jul 2016, 19:42

Re: Com Click on "Button Class"

22 Sep 2017, 03:53

Hi,

Thank you for the reply.

In your example. What would be the code to have ahk click on that button? Especially if it did not have an 'ID'.
wb.document.getelementbyclass("munchies").click() ? I know that's wrong...but without ID or name i'm pretty lost.


You are definitely correct about the div tags an the button / class. On further inspection and more research I stumbled on and modified this:

Code: Select all

Elements := {}
Elements := wb.document.getElementsByTagName("button")
Loop %  Elements.length
  if (Elements[A_Index-1].getAttribute("class") = "right view-all-orders")
    Elements[A_Index-1].click()
Again, this is for:

Code: Select all

<button class="right view-all-orders" ng-click="ordersTableCtrl.viewAllOpenOrders()" translate="fulfillment.overview.ordersTable.buttonLabel.viewAll"><span>View All Open Orders</span></button>
From my understanding this should go through the document and click on the button I want to click on?
It doesn't fail anymore but it also doesn't do anything and only runs for about a second (I put a pause before and after to see).
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Com Click on "Button Class"

22 Sep 2017, 10:22

That is code I would imagine to work. I would do diagostics with this, just to make sure:

Code: Select all

Elements := {}
Elements := wb.document.getElementsByTagName("button")
Loop %  Elements.length
{
MsgBox % Elements[A_Index-1].getAttribute("class")
  if (Elements[A_Index-1].getAttribute("class") = "right view-all-orders")
    {
    Elements[A_Index-1].click()
    MsgBox Should have clicked
    }
}
This should let you know if things are processing right. If you never get the "Should have clicked" message ,then something in the if statement is wrong. You can compare you are getting the expected value for the element with the MsgBox to diagnose that. If you are getting the "Should have clicked" message (and the MsgBox before it matched what you wanted), then you know the If is functional but something is wrong with the click method. Trying alternate ways of doing a click steps outside of my knowledge on HTML/JS, but if that's the case, you know what to research.
User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Com Click on "Button Class"

22 Sep 2017, 20:12

https://developer.mozilla.org/en-US/doc ... /classList
See the contains() method. You can do:

Code: Select all

element[A_Index - 1].classList.contains("view-all-orders")
chase1
Posts: 18
Joined: 15 Jul 2016, 19:42

Re: Com Click on "Button Class"

23 Sep 2017, 03:00

Hi,

Thanks for keeping up on the topic, really appreciate it.

Exaskryz your code with the message boxes is really helping. I have been using it to identify that I can't identify the correct object in the page :(

I also implemented the contains line, but It just returned blank messagebox's. Not sure if I am using it correctly...
MsgBox % element[A_Index - 1].classList.contains("view-all-orders")

Doesn't seem to matter how I change the tag or attribute setting in Exaskryz code, I cannot get it to find anything in the middle of the page. I believe the problem might be beacuase the button is in a table?

Here's the beginning of the code

Code: Select all

<div ng-if="ordersTableCtrl.tableData && ordersTableCtrl.tableData.docs.length !== 0">
        
And here's a little more of the end:

Code: Select all

                    </div>
                    <div class="columns small-8">
                        <ul class="actions">
                            <li>
                                <button class="right view-all-orders" ng-click="ordersTableCtrl.viewAllOpenOrders()" translate="fulfillment.overview.ordersTable.buttonLabel.viewAll"><span>View All Open Orders</span></button>
                            </li>
                       
        </div>
Should I be looking at a different method to handle the table?
Or am I even farther off track?

Again, I really appreciate all the support
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Com Click on "Button Class"

23 Sep 2017, 06:07

Hi chase1,

Your site seems to be built with the help of AngularJS.

The ng-If directive removes or recreates a portion of the DOM tree based on an expression while the ngClick directive allows you to specify custom behavior when an element is clicked. Both use expressions as parameter : maybe you could try to execute the expression instead - i.e.:

Code: Select all

WB.document.parentWindow.execScript("ordersTableCtrl.viewAllOpenOrders()")
see especially: exectute a javascript function loaded in a webbrowser control
my scripts
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Com Click on "Button Class"

05 Oct 2017, 00:32

have you try'ed the iWBlearner tool?

i ask as one thing that often is an issue with not being able to find an element by looping is the it is in an iFrame, iWBlearner tells you this

other then that A_AhkUser showed you one of the easy ways to call javascript functions from AHK, you'd most likely still need to get to the right frame to make it work.
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
chase1
Posts: 18
Joined: 15 Jul 2016, 19:42

Re: Com Click on "Button Class"

08 Oct 2017, 02:45

Hi,

I could not locate a working link to the iwblearner tool. But I download and have tried to use IE HTML Element Spy. Hasn't been too helpful. In the "page source" I can get to every tag that it identifies, but it does not list the table or any of its elements.
the javascript call that A_Ahkuser suggesting is resulting in an error but I do not think I am properly identifying the correct element.

Going to post the entire page source....hopefully someone can spot something.
chase1
Posts: 18
Joined: 15 Jul 2016, 19:42

Re: Com Click on "Button Class"

08 Oct 2017, 02:53

Ok...the source was very long and probably not very helpful.

But...should I be using a different combination of lines that go inside eachother?
Like find the parent element then look inside the parent for table, then look into the table for the button?

Or am I far off? Also...how would I do that?

Hope that makes sense.

Again, anything helps...really want to get this to work
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Com Click on "Button Class"

08 Oct 2017, 08:59

https://www.dropbox.com/s/eeu6ixizphx7j ... r.exe?dl=1

Please select the element with that take a screenshot and post it her...
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
chase1
Posts: 18
Joined: 15 Jul 2016, 19:42

Re: Com Click on "Button Class"

12 Oct 2017, 04:29

Thanks for the download link and the continued support.

I am very appreciative of everyone's help!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Frogrammer, jameswrightesq and 273 guests