How to click a button in IE with WBget

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

How to click a button in IE with WBget

22 Oct 2019, 08:19

Hi all

My problem is the following. I am trying to automate a process in Internet Explorer. I managed to do lots of stuff when i am already in my account in the website. But I needed to scope this a bit, so i made the script to start IE and go in the website but when it is a newly started window of IE, I always get asked to login anew. I managed to put the username and the password in it with following lines of code

Code: Select all

pwb.document.GetElementByID(loginname).value:="TheUsername"

And similar for the password, but after few hours of trying different stuff i still did not manage to click the button for login. I am using iWB2 Learner, the button does not have neither Name nor ID.
I tried

Code: Select all

pwb.document.getElementsByClassName("bui-button bui-button--large bui-button--wide").Click
And many different variations of this line plus few other stuff as

Code: Select all

 Send, {enter}
and etc, but this also did not work.

Is there a way to do this :?

This is the outerHTML of the button:

Code: Select all

<button class="bui-button bui-button--large bui-button--wide" type="submit"><span class="bui-button__text">Next</span></button>
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: How to click a button in IE with WBget

22 Oct 2019, 08:29

getElementsByClassName (note the plural here: elements) returns a HTMLCollection of elements (an "array-like object"), so even if there is only one element/button with this ClassName, you will need to access a specific element.

Something like this, assuming you are looking for the first element of this kind (the collection is 0-based, afaik):

Code: Select all

pwb.document.getElementsByClassName("bui-button bui-button--large bui-button--wide")[0].click()
(your specific element might have a different index, though)
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 08:53

Thank you for the fast reply.

Unfortunately, when I add index as you suggested, I get error Unknown name pointing at the Index [2] in my case.

Something else on your mind :?
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: How to click a button in IE with WBget

22 Oct 2019, 09:07

Index 2 would be the third element of this kind - does it really exist?

It is often helpful to work the details out in the browser console, using the javascript. There you should be able to see all returned elements of the HTMLCollection immediately for

Code: Select all

document.getElementsByClassName("bui-button bui-button--large bui-button--wide")
Not sure, if the IE console is nice, I always use Firefox or Chrome for this...
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 09:24

I will try doing it with selenium (chrome or firefox) this evening.

Something very strange happens, I set the value with the line

Code: Select all

 pwb.document.getElementByID("loginname").Value:="***********" 
and i tried clicking the button with simple

Code: Select all

 MouseClick,left, 1454, 434 
and it clicked the button but the moment it did click it, the username disappeared and the page acted as i have clicked the button with empty username input field. It just disappears every time i try it.

Sorry for changing the topic a bit but what could be the cause for that? Any ideas?

Regarding the index of the button, yes there is three buttons. The button i wanted to click is exactly the third one, i checked this twice. As i said i will try to use Selenium from now on so I can be able to automate processes on browsers different than IE.
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: How to click a button in IE with WBget

22 Oct 2019, 09:31

StefVelikov wrote:
22 Oct 2019, 09:24
Something very strange happens, I set the value with the line

Code: Select all

 pwb.document.getElementByID("loginname").Value:="***********"
and i tried clicking the button with simple

Code: Select all

 MouseClick,left, 1454, 434
and it clicked the button but the moment it did click it, the username disappeared and the page acted as i have clicked the button with empty username input field. It just disappears every time i try it.

Sorry for changing the topic a bit but what could be the cause for that? Any ideas?
Afaik, that usually happens, if the website/javascript monitors a specific event that is triggered by actual typing, but not by just setting the value (might be intentional to make automated logins more difficult).
I think, this has been repeatedly discussed on the forum with different attempts to solve it (the solution probably depends on the the specific website).

Selenium I don't know very well - I could rather help with Chrome.ahk...
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 09:39

Oh, reallyy, man, you're opening my eyes for lots of stuff with each of your replies. Thanks for that!

Would it be an issue if i ask if you can point me to such threads in the forum :? Or a keyword i could search for to get to them?

What would
Chrome.ahk
be? I honestly have not heard of it. Is there also a thread for that in the forum?
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: How to click a button in IE with WBget

22 Oct 2019, 09:50

I might have some bookmarks - will have to look for it later.
It can be tricky for sure. Is this webpage publicly accessible? That would probably be helpful for potential helpers...

Chrome.ahk is a pure AHK solution, made by geekdude, that uses the chrome debugging protocol to automate the Chrome browser (although other chromium-based browsers might work as well with it): https://www.autohotkey.com/boards/viewtopic.php?f=6&t=42890

I think, Selenium uses the same protocol to interface Chrome, but wraps it differently, in other syntax. In both cases, you'll have to handle again the website DOM and javascript, but with slight differences.
Not sure, Selenium might be more stable or easier to use - Chrome.ahk is still quite new (and with some minor bugs) and I am still figuring things out.
Using it, I like that I don't have to handle these third-party Selenium webdrivers that need frequent updating. But there are forum members who have some experience with Selenium and you can also automate Firefox with it.
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 10:05

Thanks for the extensive response.

The webapge is admin.booking.com. It is for companies providing properties on Booking.com .

I hope more people join the discussion and give their ideas. More ideas, more things to consider and learn!
gregster
Posts: 8999
Joined: 30 Sep 2013, 06:48

Re: How to click a button in IE with WBget

22 Oct 2019, 10:23

I quickly checked for this button in the console (Firefox, but probably doesn't matter) and I got only one matching element in that returned collection:

>>document.getElementsByClassName("bui-button bui-button--large bui-button--wide")
Result:

Code: Select all

HTMLCollection(1)
​	0: <button class="bui-button bui-button--large bui-button--wide" type="submit">
​	length: 1
​	<prototype>: HTMLCollectionPrototype { item: item(), namedItem: namedItem(), length: Getter, … }
So, this button seems to have index 0 in this collection.

Will be back later.


StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 10:30

I tried with that index as well..Does not work but i am grateful for the input and wish to help!
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 11:06

Found a solution that will do the job for the next few days but i will need a longterm one.

What i did is

Code: Select all

pwb:=WBGet()
pwb.document.getElementByID("loginname").Value :="blahblah" ; 
sleep,300
pwb.document.getElementsByClassName("bui-button bui-button--large bui-button--wide")[0].click() ; The field goes empty and i do not login but at least the field becomes active and i can write into it
sleep,1200
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,50
Send, *letter*
Sleep,100
pwb.document.getElementsByClassName("bui-button bui-button--large bui-button--wide")[0].click() ; And this gets me through the username part of the login
At first it did not work even with index 0, then the whole pwb.document started giving me errors. I wrote all anew and voila! it started working. SO MANY THANKS TO GREGSTER!!!!

Anyway, i will need a more viable solution to this problem
User avatar
rommmcek
Posts: 1473
Joined: 15 Aug 2014, 15:18

Re: How to click a button in IE with WBget

22 Oct 2019, 11:23

To condense your script a bit, you can e.g.:

Code: Select all

pw:="Password"
loop, parse, % pw
{
    Send, % A_LoopField
    sleep, 50
}
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 11:58

Have another issue, the PW starts with capital letter. Let's say it is A.
I tried
Send, A
SendRaw, A
Send, {shidtdown}a{shiftup}
But all of them didn't work in the PW field while in notepad, all of them work.

Any ideas why?

Thanks for the suggestion to shorten my code! Really appreciated
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: How to click a button in IE with WBget

22 Oct 2019, 12:01

Use innertext instead of value.
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 12:23

Thanks for the suggestion.

I will try this for sure as soon as I get home. Do you have any explanation behind this suggestion. Why would .value disappear from the input field and .innerTEXT would not?
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: How to click a button in IE with WBget

22 Oct 2019, 12:39

No. But some input fields values You can change only using innertext ot textcontent.
StefVelikov
Posts: 39
Joined: 15 Sep 2019, 09:20

Re: How to click a button in IE with WBget

22 Oct 2019, 14:30

malcev wrote: No. But some input fields values You can change only using innertext ot textcontent.
I don't know how much of the thread you read but I am able to change it even with .value , the issue comes from the fact that when the button login is clicked, it acts like the field was empty all the time although it wasn't. It was explained to me that some websites/javascripts monitor if value is send like that or it was actually typed in. So I do not see how using . innerTEXT will make it act different than .values would.
User avatar
tidbit
Posts: 1272
Joined: 29 Sep 2013, 17:15
Location: USA

Re: How to click a button in IE with WBget

22 Oct 2019, 14:42

may or may not be the issue:
getElementByID()

js/COM is case-sensitive.
should be:
getElementById()
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: How to click a button in IE with WBget

22 Oct 2019, 14:44

If You see that text in input field has changed - it is does not mean that value of this input has changed.
Just use innertext instead of value and it will work with this site.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, ulysim and 312 guests