Blackcarbon Posted July 2, 2019 Share Posted July 2, 2019 Hi There, I am currently working on the autoit script, where would like to make use of the same script to load different webpages having different different form types: Would like to know if we can make use of the "_IEFormGetCollection" under condition for "If and ElseIf" condition as below: If $oForm = _IEFormGetCollection($oIE,"ReLoginForm") Then $oUser1 = _IEFormElementGetObjByName($oForm, "j_username") ElseIf $oForm = _IEFormGetCollection($oIE,"LogonForm") $oUser1 = _IEFormElementGetObjByName($oForm, "name1") EndIf _IEFormElementSetValue($oUser1, "username") Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 2, 2019 Moderators Share Posted July 2, 2019 Moved to the appropriate forum. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 2, 2019 Share Posted July 2, 2019 Hi @Srininaik, and welcome to the AutoIt forums You should look more in the Help file for the use of _IEFormGetCollection. In the first place, it returns a collection of form objects in case of success, or sets the @error flag to non-zero value; The second parameter of the function is an integer, and not a string; Explain what do you want to do in detail, so we can assist you more Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Blackcarbon Posted July 3, 2019 Author Share Posted July 3, 2019 Hi @FrancescoDiMuro, Thanks for your response. I believe this explains the below from the 2 points confirms that "If condition" wouldnt work in my case: In the first place, it returns a collection of form objects in case of success, or sets the @error flag to non-zero value; The second parameter of the function is an integer, and not a string I am trying to write a simple script to automate to supply (User creds) which could cater for different webpages with the different form names and attributes using "If ElseIF condition", For example: https://www.abc.com (Form name: "ReLoginForm" , Userinput ID: "j_username") https://www.def.com (Form name: "LogonForm" , Userinput ID: "g_username") I got it working in a separate scripts, but trying to combine it to one by using the Conditions. Let me revisit the conditions and will keep you posted. Thanks Link to comment Share on other sites More sharing options...
Subz Posted July 3, 2019 Share Posted July 3, 2019 Just create a function basic example: nb: Included two demo sites that actually had login forms. #include <IE.au3> _Logon("http://www.demo.amitjakhu.com/login-form/", "login-form", "username", "My Username") _Logon("https://wpforms.com/demo/user-login-form-demo/", "wpforms-form-264018", "wpforms-264018-field_0", "My Other Username") ;~ _Logon("https://www.abc.com", "ReLoginForm", "j_username", "username") ;~ _Logon("https://www.def.com", "LogonForm", "g_username", "username") Func _Logon($_sURL, $_sFormName, $_sUserTagID, $_sUserName = "username") Local $oIE = _IECreate($_sURL, 1) Sleep(3000) If @error Then Return MsgBox(4096, "_IECreate", "Unable to Connect to: " & $_sURL) Local $oFormName = _IEFormGetObjByName($oIE, $_sFormName) If @error Then Return MsgBox(4096, "_IEFormGetObjByName", "Error occurred connecting to form: " & $_sFormName) Local $oUserTagID = _IEFormElementGetObjByName($oFormName, $_sUserTagID) If @error Then Return MsgBox(4096, "_IEFormElementGetObjByName", "Error occurred connecting to form element: " & $_sUserTagID) _IEFormElementSetValue($oUserTagID, $_sUserName) If @error Then Return MsgBox(4096, "_IEFormElementSetValue", "Error occurred setting form element: " & $_sUserName) EndFunc Link to comment Share on other sites More sharing options...
Blackcarbon Posted July 4, 2019 Author Share Posted July 4, 2019 Thanks @Subz I was able to use the function as mentioned in the above script and able to pass the creds. Using the above code, I will be running one webpage at a time i.e. either: https://www,abc,com or https://www.def.com (When run the test, the script works, however since there is other form details 'Warning messages for missing webpage logonform details is presented as below) --> IE.au3 T3.0-2 Warning from function _IEAttach, $_IESTATUS_NoMatch --> IE.au3 T3.0-2 Warning from function _IEFormElementGetObjByName, $_IESTATUS_NoMatch Suppressing the warning messages is a workaround for now:) Thanks again Link to comment Share on other sites More sharing options...
Subz Posted July 4, 2019 Share Posted July 4, 2019 Warnings are normal behavior unless you suppress them, the @error below each function should capture the error and return without crashing the script altogether. 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