cassetcd

Simply need to click a webpage button

10 posts in this topic

Hello all, 

I am brand-new to scripting and I have stumbled my way through filling the sign in boxes on a webpage, but I can't figure out how to click the Log In button other than with MouseClick, and that breaks when the user changes the size of the window. This is one of the last elements I'm missing; can someone help me out?

The log in button I need to click is on this page: 

https://www.asrpro.com/Login.aspx

 

Thanks!

Chad

Share this post


Link to post
Share on other sites



Forgot to add I'm doing this in Internet Explorer.

Share this post


Link to post
Share on other sites

You didn't show your code, so it leaves us guessing what you have already tried. Have you looked into _IEFormSubmit?

Share this post


Link to post
Share on other sites

Welcome to AutoIt please try:

#include <IE.au3>

;~ Connect to the site
Local $oIE = _IECreate("https://www.asrpro.com/Login.aspx", 1)
;~ Wait for the site to load
_IELoadWait($oIE)
;~ Get all Inputs
Local $oInputs = _IETagNameGetCollection($oIE, "Input")
For $oInput In $oInputs
    ;~ Fill in Username Field
    If $oInput.id = 'username' Then $oInput.value = 'Username'
    ;~ Fill in Password Field
    If $oInput.id = 'password' Then $oInput.value = 'Password'
    ;~ Fill in Id Field
    If $oInput.id = 'context' Then $oInput.value = 'Id#'
Next
;~ Get all Buttons
Local $oButtons = _IETagNameGetCollection($oIE, "Button")
For $oButton In $oButtons
    ;~ Check if Button InnerText equals Log In and perform an action.
    ;~ Uncomment the _IEAction line below to submit the form.
    If $oButton.InnerText = 'Log In' Then
        MsgBox(64, 'Log In Button Found', 'Button found with value: ' & $oButton.InnerText)
        ;_IEAction($oButton, 'click')
    EndIf
Next

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

32 minutes ago, Danp2 said:

You didn't show your code, so it leaves us guessing what you have already tried. Have you looked into _IEFormSubmit?

Here's the whole thing as it currently stands; it logs into the site and opens the page I need displayed:

 

#include <IE.au3>

Call ("SignIn")

Func SignIn ()

Global $oIE = _IECreate ("https://www.asrpro.com/Login.aspx")
Local $username = _IEGetObjByName ($oIE, "username")
Local $password = _IEGetObjByName ($oIE, "Password")
Local $context = _IEGetObjByName ($oIE, "Context")

_IEFormElementSetValue ($username, "myname")
_IEFormElementSetValue ($password, "myPassword")
_IEFormElementSetValue ($Context, "myID")

WinSetState ( "Inspect - Internet Explorer", "", @SW_MAXIMIZE)


MouseClick ("left", 970, 725)

Sleep (5000)

_IENavigate ($oIE, "https://www.asrpro.com/Parts/Dashboard")



EndFunc

 

 

Edited by JLogan3o13

Share this post


Link to post
Share on other sites

Subz, 

 

When I paste your code and use my login info I get the MsgBox pop up: Button found with value: Log in but the button isn't clicked (i.e. nothing else happens)

Share this post


Link to post
Share on other sites

Notice the commented section below the MsgBox:

;_IEAction($oButton, 'click')

Try un-commenting


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
3 minutes ago, JLogan3o13 said:

Notice the commented section below the MsgBox:

;_IEAction($oButton, 'click')

Try un-commenting

That certainly would help. I didn't see it until you pointed it out. 

 

Thanks! It works now.

Share this post


Link to post
Share on other sites

Here's the "traditional" method --

#include <IE.au3>

SignIn()

Func SignIn ()

Global $oIE = _IECreate ("https://www.asrpro.com/Login.aspx")

Local $oForm = _IEFormGetCollection($oIE, 0)
Local $username = _IEFormElementGetObjByName ($oForm, "username")
Local $password = _IEFormElementGetObjByName ($oForm, "Password")
Local $context = _IEFormElementGetObjByName ($oForm, "Context")

_IEFormElementSetValue ($username, "myname")
_IEFormElementSetValue ($password, "myPassword")
_IEFormElementSetValue ($Context, "myID")

_IEFormSubmit($oForm)

EndFunc

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now