Jump to content

Recommended Posts

Posted

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

  • Moderators
Posted

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Hi @Srininaik, and welcome to the AutoIt forums :welcome:
You should look more in the Help file for the use of _IEFormGetCollection.

  1. In the first place, it returns a collection of form objects in case of success, or sets the @error flag to non-zero value;
  2. The second parameter of the function is an integer, and not a string;
  3. 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:

 

Posted

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:

  1. In the first place, it returns a collection of form objects in case of success, or sets the @error flag to non-zero value;
  2. 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

Posted

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

 

Posted

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

 

Posted

Warnings are normal behavior unless you suppress them, the @error below each function should capture the error and return without crashing the script altogether.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...