twillster Posted October 23, 2008 Share Posted October 23, 2008 Okay, I'm working on this little bit of automated business and am having some difficulties. Here's my code. CODE #include <IE.au3> AutoItSetOption("TrayIconDebug",1) ProgressOn("Adding User to Message Labs","Starting Process...","0 percent",200,200,16) ProgressSet ( 5 , "5 percent" , "Connect to site...") $oIE = _IECreate("http://site.logon.page",0,1,1,1) ProgressSet ( 15 , "15 percent" , "Authenticating") $o_form = _IEFormGetObjByName($oIE,"lform") $o_uname = _IEFormElementGetObjByName($o_form,"in_tx_username") $o_pw = _IEFormElementGetObjByName($o_form,"in_pw_userpass") $username = "username" $password = "password" _IEFormElementSetValue($o_uname,$username,1) _IEFormElementSetValue($o_pw,$password,1) $oButton = _IEFormElementGetObjByName($o_Form, "in_su_dologin508") _IEAction($oButton, "click") _IELoadWait($oIE) ProgressSet ( 20 , "20 percent" , "Loading page") _IENavigate($oIE,"http://site.configuration.page",1) _IELoadWait($oIE) Sleep(700) ProgressSet ( 25 , "25 percent" , "Get form information") $o_form = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_dropdown = _IEFormElementGetObjByName($o_form,"dropdownlistDomains:ddlDomains") ProgressSet ( 30 , "30 percent" , "Choose domain") $emaildomain = "mydomain.com" If $emaildomain == "mydomain.com" Then _IEFormElementOptionselect($o_dropdown,"mydomain.com",1,"byText",1) ElseIf $emaildomain == "my-domain.com" Then _IEFormElementOptionselect($o_dropdown,"my-domain.com",1,"byText",1) EndIf ProgressSet ( 35 , "35 percent" , "Add new address") _IELinkClickByText($o_form,"New Address") Sleep(700) ProgressSet ( 40 , "40 percent" , "Attach to new window") $oIE = _IEAttach("Registered Users","Title") _IELoadWait($oIE) Sleep(700) ProgressSet ( 45 , "45 percent" , "Get form information") $o_newform = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_email = _IEFormElementGetObjByName($o_newform,"AddAddress:textboxEmail") $email1 = "petej" Sleep(700) ProgressSet ( 50 , "50 percent" , "Add address " & $email1) _IEFormElementSetValue($o_email,$email1,1) _IELinkClickByText($o_newform,"Add") Sleep(5000) ;;; DIES RIGHT IN HERE BUT I'M GUESSING IT'S SOMEWHERE WHEN THE IELinkClickByText FUNCTION RUNS. ; The Progress set right there gets posted and then will not move from that spot. ProgressSet ( 55 , "55 percent" , "Re-attach to old window") $oIE = _IEAttach("Platform","Title") Sleep(5000) ProgressSet ( 60 , "60 percent" , "Get form information") $o_form = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_dropdown = _IEFormElementGetObjByName($o_form,"dropdownlistDomains:ddlDomains") ProgressSet ( 65 , "65 percent" , "Choose domain") If $emaildomain == "mydomain.com" Then _IEFormElementOptionselect($o_dropdown,"mydomain.com",1,"byText",1) ElseIf $emaildomain == "my-domain.com" Then _IEFormElementOptionselect($o_dropdown,"my-domain.com",1,"byText",1) EndIf ProgressSet ( 70 , "70 percent" , "Add new address") _IELinkClickByText($o_form,"New Address") Sleep(2000) ProgressSet ( 75 , "75 percent" , "Attach to new window") $oIE = _IEAttach("Registered Users","Title") Sleep(1000) ProgressSet ( 80 , "80 percent" , "Get form information") $o_newform = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_email = _IEFormElementGetObjByName($o_newform,"AddAddress:textboxEmail") $email2 = "pete.jones" ProgressSet ( 85 , "85 percent" , "Add address" & $email2) _IEFormElementSetValue($o_email,$email2,1) ProgressSet ( 90 , "90 percent" , "Add new address") _IELinkClickByText($o_newform,"Add") ProgressSet ( 95 , "95 percent" , "Re-attach to old window") Sleep(5000) $oIE = _IEAttach("Platform","Title") Sleep(2000) ProgressSet ( 100 , "100 percent" , "Log off web service") _IENavigate($oIE,"http://site.logout.link",1) ProgressOff() Exit So this bit of code logs the user in, then navigates to a different part of the site. Once there it changes a drop down... waits for the page to change from the dropdown and then clicks a button. Then a pop-up comes up, it gets form information and fills in a field then clicks a link on the pop-up page. Occasionally it will get stuck on line 675 of IE.au3 in a Sleep(100). It never moves from that position. sometimes it will work fine and other times it just stops. If you look at the code closely at all you'll see that I perform the same series of actions 2 times. First time for one email address and the second time for another email address. What i'm trying to figure out is why Sleep in the _IELoadWait function is called when I am not calling it myself. I have tried monkeying with adding more Sleeps in the whole mix but it doesn't seem to matter. The LinkClickByText clicks a button which does close that pop-up if that helps at all. Thanks in advance. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 23, 2008 Share Posted October 23, 2008 (edited) Okay, I'm working on this little bit of automated business and am having some difficulties. Here's my code. CODE #include <IE.au3> AutoItSetOption("TrayIconDebug",1) ProgressOn("Adding User to Message Labs","Starting Process...","0 percent",200,200,16) ProgressSet ( 5 , "5 percent" , "Connect to site...") $oIE = _IECreate("http://site.logon.page",0,1,1,1) ProgressSet ( 15 , "15 percent" , "Authenticating") $o_form = _IEFormGetObjByName($oIE,"lform") $o_uname = _IEFormElementGetObjByName($o_form,"in_tx_username") $o_pw = _IEFormElementGetObjByName($o_form,"in_pw_userpass") $username = "username" $password = "password" _IEFormElementSetValue($o_uname,$username,1) _IEFormElementSetValue($o_pw,$password,1) $oButton = _IEFormElementGetObjByName($o_Form, "in_su_dologin508") _IEAction($oButton, "click") _IELoadWait($oIE) ProgressSet ( 20 , "20 percent" , "Loading page") _IENavigate($oIE,"http://site.configuration.page",1) _IELoadWait($oIE) Sleep(700) ProgressSet ( 25 , "25 percent" , "Get form information") $o_form = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_dropdown = _IEFormElementGetObjByName($o_form,"dropdownlistDomains:ddlDomains") ProgressSet ( 30 , "30 percent" , "Choose domain") $emaildomain = "mydomain.com" If $emaildomain == "mydomain.com" Then _IEFormElementOptionselect($o_dropdown,"mydomain.com",1,"byText",1) ElseIf $emaildomain == "my-domain.com" Then _IEFormElementOptionselect($o_dropdown,"my-domain.com",1,"byText",1) EndIf ProgressSet ( 35 , "35 percent" , "Add new address") _IELinkClickByText($o_form,"New Address") Sleep(700) ProgressSet ( 40 , "40 percent" , "Attach to new window") $oIE = _IEAttach("Registered Users","Title") _IELoadWait($oIE) Sleep(700) ProgressSet ( 45 , "45 percent" , "Get form information") $o_newform = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_email = _IEFormElementGetObjByName($o_newform,"AddAddress:textboxEmail") $email1 = "petej" Sleep(700) ProgressSet ( 50 , "50 percent" , "Add address " & $email1) _IEFormElementSetValue($o_email,$email1,1) _IELinkClickByText($o_newform,"Add") Sleep(5000) ;;; DIES RIGHT IN HERE BUT I'M GUESSING IT'S SOMEWHERE WHEN THE IELinkClickByText FUNCTION RUNS. ; The Progress set right there gets posted and then will not move from that spot. ProgressSet ( 55 , "55 percent" , "Re-attach to old window") $oIE = _IEAttach("Platform","Title") Sleep(5000) ProgressSet ( 60 , "60 percent" , "Get form information") $o_form = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_dropdown = _IEFormElementGetObjByName($o_form,"dropdownlistDomains:ddlDomains") ProgressSet ( 65 , "65 percent" , "Choose domain") If $emaildomain == "mydomain.com" Then _IEFormElementOptionselect($o_dropdown,"mydomain.com",1,"byText",1) ElseIf $emaildomain == "my-domain.com" Then _IEFormElementOptionselect($o_dropdown,"my-domain.com",1,"byText",1) EndIf ProgressSet ( 70 , "70 percent" , "Add new address") _IELinkClickByText($o_form,"New Address") Sleep(2000) ProgressSet ( 75 , "75 percent" , "Attach to new window") $oIE = _IEAttach("Registered Users","Title") Sleep(1000) ProgressSet ( 80 , "80 percent" , "Get form information") $o_newform = _IEFormGetObjByName($oIE,"frmAddresses_565") $o_email = _IEFormElementGetObjByName($o_newform,"AddAddress:textboxEmail") $email2 = "pete.jones" ProgressSet ( 85 , "85 percent" , "Add address" & $email2) _IEFormElementSetValue($o_email,$email2,1) ProgressSet ( 90 , "90 percent" , "Add new address") _IELinkClickByText($o_newform,"Add") ProgressSet ( 95 , "95 percent" , "Re-attach to old window") Sleep(5000) $oIE = _IEAttach("Platform","Title") Sleep(2000) ProgressSet ( 100 , "100 percent" , "Log off web service") _IENavigate($oIE,"http://site.logout.link",1) ProgressOff() Exit So this bit of code logs the user in, then navigates to a different part of the site. Once there it changes a drop down... waits for the page to change from the dropdown and then clicks a button. Then a pop-up comes up, it gets form information and fills in a field then clicks a link on the pop-up page. Occasionally it will get stuck on line 675 of IE.au3 in a Sleep(100). It never moves from that position. sometimes it will work fine and other times it just stops. If you look at the code closely at all you'll see that I perform the same series of actions 2 times. First time for one email address and the second time for another email address. What i'm trying to figure out is why Sleep in the _IELoadWait function is called when I am not calling it myself. I have tried monkeying with adding more Sleeps in the whole mix but it doesn't seem to matter. The LinkClickByText clicks a button which does close that pop-up if that helps at all. Thanks in advance. Some functions in the IE.au3 UDF call _IELoadWait() internally, and _IELinkClickByText() is one of them. Try setting the $f_wait = 0 parameter, as long as you think it through and realize that the script will not wait for "complete" status from the page before continuing after _IELinkClickByText() with that setting. For example: ProgressSet(35, "35 percent", "Add new address") _IELinkClickByText($o_form, "New Address", 0, 0); no wait ProgressSet(40, "40 percent", "Attach to new window") $iTimer = TimerInit(); Initialize timer While 1 ; Test for 'Registered Users' every 250ms $oIE = _IEAttach("Registered Users", "Title") If @error Then ; Test 10sec timeout If TimerDiff($iTimer) >= 10000 Then MsgBox(16, "Error", "Timeout occured: 'Registered Users' did not appear before timeout.") Exit EndIf Else _IELoadWait($oIE) EndIf Sleep(250) WEnd Edit: Added example. Edited October 23, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
twillster Posted October 23, 2008 Author Share Posted October 23, 2008 That's great Psalty.... didn't even consider that as an option. Quick 2nd question for you. Is there a way to make existing windows hidden/invisible? In the case of this script I want the progress bar to be the only thing seen but the pop-up created by the link click earlier on is visible rather than inheriting the "hidden" attribute of its parent. Thanks for all your help. I'd be pretty lost in here without you right now. Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 23, 2008 Share Posted October 23, 2008 That's great Psalty.... didn't even consider that as an option.Quick 2nd question for you. Is there a way to make existing windows hidden/invisible? In the case of this script I want the progress bar to be the only thing seen but the pop-up created by the link click earlier on is visible rather than inheriting the "hidden" attribute of its parent.Thanks for all your help. I'd be pretty lost in here without you right now.(Note the edit where I added an example.)I don't think you can keep the popup from being initially visible, but you can watch for it in a loop and hide it within milliseconds once it appears. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
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