Chance1 Posted July 5, 2017 Posted July 5, 2017 (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 July 5, 2017 by Chance1
SkysLastChance Posted July 5, 2017 Posted July 5, 2017 (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 July 5, 2017 by SkysLastChance You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
Chance1 Posted July 5, 2017 Author Posted July 5, 2017 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)
Chance1 Posted July 5, 2017 Author Posted July 5, 2017 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?
SkysLastChance Posted July 5, 2017 Posted July 5, 2017 (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 July 5, 2017 by SkysLastChance You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott
Chance1 Posted July 5, 2017 Author Posted July 5, 2017 unfortunately I cannot because it is business related.
Chance1 Posted July 5, 2017 Author Posted July 5, 2017 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.
Danp2 Posted July 5, 2017 Posted July 5, 2017 Post the normalLogin Javascript function. Latest Webdriver UDF Release Webdriver Wiki FAQs
Chance1 Posted July 6, 2017 Author Posted July 6, 2017 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(); } };
Danp2 Posted July 6, 2017 Posted July 6, 2017 Have you tried using _IEFormSubmit instead of clicking the button? Latest Webdriver UDF Release Webdriver Wiki FAQs
boy233 Posted July 6, 2017 Posted July 6, 2017 Quote I think that works! Sleep(2000) _IEImgClick ($oIE, "/xmlpserver/xdo/images/spacer.gif", "src") _IELoadWait($oIE)
Chance1 Posted July 6, 2017 Author Posted July 6, 2017 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
Chance1 Posted July 6, 2017 Author Posted July 6, 2017 (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 July 6, 2017 by Chance1
Danp2 Posted July 6, 2017 Posted July 6, 2017 Did you try this (from ex2 of _IEAction in help file)? _IEAction($o_signin, "focus") ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") Latest Webdriver UDF Release Webdriver Wiki FAQs
boy233 Posted July 6, 2017 Posted July 6, 2017 I do not believe... :S Try this ... $oIE2 = _IEAttach("Title of the Page") _IEImgClick ($oIE2, "X", "alt") Sleep(3000) I hope it works now!
Danp2 Posted July 6, 2017 Posted July 6, 2017 @boy233 How does clicking on the spacer image address his issue? Latest Webdriver UDF Release Webdriver Wiki FAQs
boy233 Posted July 6, 2017 Posted July 6, 2017 @Danp2 Unfortunately in my HTML there is no image only Div with OnClick ... I can not click! :S
Danp2 Posted July 6, 2017 Posted July 6, 2017 @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"> Latest Webdriver UDF Release Webdriver Wiki FAQs
boy233 Posted July 6, 2017 Posted July 6, 2017 @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)
Chance1 Posted July 6, 2017 Author Posted July 6, 2017 @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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now