Chance1

Click onclick Button Javascript

37 posts in this topic

#1 ·  Posted (edited)

Hey Guys, I am trying to automate a user sign in, and I am able to populate the username and password, but I am not able to click the Sign In button. I am about to get the correct information from the button because I tested it with a msgbox. Here is the code I currently have:

Local $o_form = _IEFormGetObjByName ($oIE, "loginform")
    
    Local $o_user = _IEFormElementGetObjByName ($o_form, "id")
    Local $o_password = _IEFormElementGetObjByName ($o_form, "passwd")
    Local $o_signin = _IEFormElementGetObjByName ($o_form, "SUBMIT_BUTTON")

    _IELoadWait($oIE)
    MsgBox(4096,"test", _IEFormElementGetValue($o_signin))
    Sleep(100)
    
    _IEFormElementSetValue ($o_user, $TargetUsername)
    Sleep(100)
    _IEFormElementSetValue ($o_password, $TargetPassword)
    Sleep(100)
    _IEAction($o_signin, "click")
    Sleep(100)

And here is the information from the site:

<!--  Sign in button -->
<img width="5" height="10" alt="X" src="/xmlpserver/xdo/images/spacer.gif">
<input name="SUBMIT_BUTTON" title="Please enter username and password" class="submitButtonEnable button" style="width: 120px;" onclick="normalLogin(event);" type="submit" value="Sign In">

Any ideas guys? I have search the forums and I could not find the answer to my problem. Anything would be help, thanks!

Edited by Chance1

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput in $oInputs
    If StringStripWS($oInput.value, 7) = "Sign In" Then _IEAction($oInput, "click")
Next

@Subz helped me with a similar question. Give this a try. 

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#3 ·  Posted

tested it a couple times with no luck, I will keep trying. Just to be sure, the code you provided would just be in place of the "_IEAction($0_signin, "click") in my original post? Like so:

Local $o_form = _IEFormGetObjByName ($oIE, "loginform")
    
    Local $o_user = _IEFormElementGetObjByName ($o_form, "id")
    Local $o_password = _IEFormElementGetObjByName ($o_form, "passwd")
    Local $o_signin = _IEFormElementGetObjByName ($o_form, "SUBMIT_BUTTON")

    _IELoadWait($oIE)
    MsgBox(4096,"test", _IEFormElementGetValue($o_signin))
    Sleep(100)
    
    _IEFormElementSetValue ($o_user, $TargetUsername)
    Sleep(100)
    _IEFormElementSetValue ($o_password, $TargetPassword)
    Sleep(100)
    
    Local $oInputs = _IETagNameGetCollection($oIE, "input")

    For $oInput in $oInputs
        If StringStripWS($oInput.value, 7) = "Sign In" Then _IEAction($oInput, "click")
    Next
    sleep(100)

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

I have tried a couple different variations of the code you provide, changing the if statement and such, still not luck.I  was testing it and saw that it does go into the Then clause but still no click occurred. Any idea why?

Why would I want to check the input without white space?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

It strips white space from the beginning and end of a string and also remove double spaces. I asked the same question. Ha-ha as subz told me you probably don't even need it. 

 

Can you post the full html code of the site or give the url?

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#6 ·  Posted

unfortunately I cannot because it is business related.

Share this post


Link to post
Share on other sites

#7 ·  Posted

think it could be something with the way it is clicking? I have seen on a couple different forums that you have to fire the onmouseodwn and onmouseup events. I tried it but with no luck, this is what I tried:

Local $oInputs = _IETagNameGetCollection($oIE, "input")
    For $oInput in $oInputs
        If StringStripWS($oInput.value, 7) = "Sign In" Then 
            $oInput.fireEvent("onmousedown")
            $oInput.fireEvent("onmouseup")
            _IEAction($oInput, "click")
        EndIf
    Next

Keep in mind I have never tried to trigger events so I could be trying to do this complete wrong. Any thoughts on this or know how I could clean up my syntax? Thanks. 

Share this post


Link to post
Share on other sites

#8 ·  Posted

Post the normalLogin Javascript function.

Share this post


Link to post
Share on other sites

#9 ·  Posted

 

function normalLogin(event){
     if(event && event.preventDefault)
     {
       event.preventDefault(); 
     }
     else
     {
       event.returnValue = false;
     }
     var errMsg = "Please enter username and password";
     if(document.loginform.id.value == null || '' == document.loginform.id.value)
     {
       alert(errMsg);
       return false;
     }
     else
     {
       document.loginform.submit();  
     }
   };

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

Have you tried using _IEFormSubmit instead of clicking the button?

Share this post


Link to post
Share on other sites

#11 ·  Posted

Quote

I think that works!

Sleep(2000)
_IEImgClick ($oIE, "/xmlpserver/xdo/images/spacer.gif", "src")
_IELoadWait($oIE)

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

26 minutes ago, Danp2 said:

Have you tried using _IEFormSubmit instead of clicking the button?

I tired using 

sleep(2000)
_IEFormSubmit($o_form)
sleep(100)

with no luck

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

38 minutes ago, boy233 said:

I think that works!

Sleep(2000)
_IEImgClick ($oIE, "/xmlpserver/xdo/images/spacer.gif", "src")
_IELoadWait($oIE)

 

I tired it and also had no luck. I also tried 

sleep(2000)
_IEFormImageClick ($oIE, "/xmlpserver/xdo/images/spacer.gif", "src")
_IELoadWait($oIE)

but I ended up getting an error in the IE.au3 script. I also tried this, where $o_signin is the "Sign On" button, also no luck.

sleep(2000)
    _IEImgClick ($o_signin, "/xmlpserver/xdo/images/spacer.gif", "src")
    _IELoadWait($oIE)

 

Edited by Chance1

Share this post


Link to post
Share on other sites

#14 ·  Posted

Did you try this (from ex2 of _IEAction in help file)?

_IEAction($o_signin, "focus")
ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

I do not believe... :S
Try this ...

$oIE2 = _IEAttach("Title of the Page")
_IEImgClick ($oIE2, "X", "alt")
Sleep(3000)

I hope it works now!

Share this post


Link to post
Share on other sites

#16 ·  Posted

@boy233 How does clicking on the spacer image address his issue?

Share this post


Link to post
Share on other sites

#17 ·  Posted

@Danp2 Unfortunately in my HTML there is no image only Div with OnClick ... I can not click! :S

Share this post


Link to post
Share on other sites

#18 ·  Posted

@boy233 Sorry, but your reply makes no sense to me. The code you posted is pointing at

<img width="5" height="10" alt="X" src="/xmlpserver/xdo/images/spacer.gif">

when the goal is to click this

<input name="SUBMIT_BUTTON" title="Please enter username and password" class="submitButtonEnable button" style="width: 120px;" onclick="normalLogin(event);" type="submit" value="Sign In">

 

Share this post


Link to post
Share on other sites

#19 ·  Posted

@Danp2 Sorry you're correct ... If the button was image it would work!

I think that's how it works !

$oForm = _IEFormGetObjByName ($oIE, "Form Name")
_IEFormSubmit($oForm, 0)

 

Share this post


Link to post
Share on other sites

#20 ·  Posted

@Danp2 That is a very clever idea. I cannot seem to get it working but maybe I am getting the handle wrong. I am trying this, 

local $hWnd = _IEAction($oIE, "hwnd")
sleep(200)  
_IEAction($o_signin, "focus")
sleep(200)
ControlSend($hWnd, '', "[CLASS:Internet Exploerer_server; INSTANCE:1]", "{ENTER}")
sleep(200)

But it was not working

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