Jump to content

Selecting a Dropdown in IE


Recommended Posts

Hi Can you check what I'm doing wrong? 

I am trying to select a dropdown in IE 

I get below error on console 

 

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "H:\Quality Assurance\AutoIT Scripts\Framework\TestEnv.au3"    

Loading URL 
$ClientRegOfficeCityID equals: 
$ClientRegOffice1ID equals: 
$ClientRegOffficeStateID equals: --> IE.au3 T3.0-2 Error from function _IETagNameGetCollection, $_IESTATUS_NoMatch
"H:\Quality Assurance\AutoIT Scripts\Framework\Tests\Test01CreateAClient.au3" (118) : ==> Variable must be of type "Object".:
$DropdownBusinessSectorCodeSelect.focus
$DropdownBusinessSectorCodeSelect^ ERROR
>Exit code: 1    Time: 30.24

The HTML for the drop down is here

<select class="form-control input-validation-error" name="businessSectorCode" data-val="true" data-val-remote="Business Sector Code must be selected" data-val-remote-additionalfields="*.BusinessSectorCode" data-val-remote-url="/Home/CheckBusinessSectorCode" id="Client_BusinessSectorCode" aria-invalid="true" aria-describedby="Client_BusinessSectorCode-error">

The bit of code where I select the dropdown is here

Sleep(4000)
MouseWheel($MOUSE_WHEEL_down, 10)

Sleep(3000)

$DropdownBusinessSectorCodeID = _IEGetObjById($oIE, "Client_BusinessSectorCode")
$DropdownBusinessSectorCodeSelect = _IETagNameGetCollection($DropdownBusinessSectorCodeID, "select", 1)
$DropdownBusinessSectorCodeSelect.focus
   If @error Then
      ConsoleWrite(@CRLF & "Can't focus drop down for Business Sector Code")

   EndIf

_IEFormElementOptionSelect($DropdownBusinessSectorCodeSelect, "Accountants (CACC)", 1, "byText")
   If @error Then
      ConsoleWrite(@CRLF & "Can't change drop down for Business Sector Code")

   EndIf

And the full code for the webpage is this 

If I comment out the dropdown bit it inputs all the data OK and is able to run my CheckFieldEquals function OK. You'll notice I commented out the IEAttach but if I let that run it doesn't work at all. 

 

;/********************************************************************************************/
 ;/************************* Maximise screen***************************************************/
  ;/********************************************************************************************/
Func Test01CreateACilent($URL, $ClientName, $ClientRegOffice1, $ClientRegOffice2, $ClientRegOfficeCity, $ClientRegOffficeState, $ClientRegOfficePostCode, $ClientContact1, $ClientContactPhoneNo,$ClientRelationshipPartner, $ClientReferringPartner)

   ;/************************* Start URL for compliance letters **************************/
ConsoleWrite(@CRLF & "Loading URL ")

Local $oIE = _IECreate($URL, 1)
;WinWait($ApplicationWindow, 10)
;ConsoleWrite(@CRLF & "Waiting for window")
;
;;attach ie window
;Sleep(10000)
;ConsoleWrite(@CRLF & "Getting handle")
;
$hWnd = WinWait($ApplicationWindow, "" , 10 )
;Sleep(5000)
;
;
;
;ConsoleWrite(@CRLF & "Activating Window")
;WinActivate($ApplicationWindow)
;ConsoleWrite(@CRLF & "Attaching IEATTach for window")
;

 ;/****************************End*************************************************************/

;/****************************Test Submit button *********************************************/
   ;Press Search button
    sleep(10000)


;~ Get all Buttons
Local $oButtons = _IETagNameGetCollection($oIE, "Button")
For $oButton In $oButtons
    ;~ Check if Button InnerText equals Log In and perform an action.
    ;~ Uncomment the _IEAction line below to submit the form.
    If $oButton.InnerText = "Submit"       Then
       if @Error then
          ConsoleWrite(@CRLF & "Error finding submit button")

          Endif
        MsgBox(64, 'Log In Button Found', 'Button found with value: ' & $oButton.InnerText, 2)
        Sleep(2500)
        _IEAction($oButton, 'click')
        ExitLoop
        Sleep(4000)
    EndIf
 Next

;$oIE = _IEAttach($hWnd)

if @error then
   ConsoleWrite("Unable to attach IE window" & $hWnd)
   MsgBox($MB_SYSTEMMODAL, "Error handling  ", "Can't attach IE Window ", 4)

   EndIf

   if WinSetState($ApplicationWindow, "", @SW_MAXIMIZE) Then


Else
   Sleep(6000)
   WinSetState($ApplicationWindow, "", @SW_MAXIMIZE)
EndIf
_IELoadWait($oIE)
Sleep(0400)


;Get IDs of boxes
$ClientNameID = _IEGetObjByID($oIE, "Client_Name")
$ClientRegOffice1ID = _IEGetObjByID($oIE, "Client_RegisteredOfficeFirstLine")

$ClientRegOffice2ID = _IEGetObjByID($oIE, "Client_RegisteredOfficeSecondLine")

$ClientRegOfficeCityID = _IEGetObjByID($oIE, "Client_RegisteredOfficeThirdLine")
$ClientRegOffficeStateID  = _IEGetObjByID($oIE, "Client_RegisteredOfficeFourthLine")
$ClientRegOfficePostCodeID = _IEGetObjByID($oIE, "Client_RegisteredOfficePostcode")
$ClientContact1ID = _IEGetObjByID($oIE, "Client_ContactName")
$ClientContactPhoneNoID = _IEGetObjByID($oIE, "Client_TelephoneNumber")
$ClientRelationshipPartnerID = _IEGetObjByID($oIE, "Client_ClientRelationshipPartner")
$ClientReferringPartnerID = _IEGetObjByID($oIE, "Client_ReferringPartner")


;Input variables declared in the function of this test (defined on the TestEnv file)
_IEFormElementSetValue($ClientNameID, $ClientName)
_IEFormElementSetValue($ClientRegOffice1ID, $ClientRegOffice1)
ConsoleWrite(@CRLF & "$ClientRegOfficeCityID equals: " & $ClientRegOfficeCityID)

_IEFormElementSetValue($ClientRegOffice2ID, $ClientRegOffice2)
If @Error Then
   ConsoleWrite(@CRLF & "Unable to input Street box using variable:$ClientRegOffice2ID " & $ClientRegOffice2ID)
EndIf



_IEFormElementSetValue($ClientRegOfficeCityID, $ClientRegOfficeCity)
ConsoleWrite(@CRLF & "$ClientRegOffice1ID equals: " & $ClientRegOffice1ID)

_IEFormElementSetValue($ClientRegOffficeStateID, $ClientRegOffficeState)
ConsoleWrite(@CRLF & "$ClientRegOffficeStateID equals: " & $ClientRegOffficeStateID)

_IEFormElementSetValue($ClientRegOfficePostCodeID, $ClientRegOfficePostCode)
_IEFormElementSetValue($ClientContact1ID, $ClientContact1)
_IEFormElementSetValue($ClientContactPhoneNoID, $ClientContactPhoneNo)
_IEFormElementSetValue($ClientRelationshipPartnerID, $ClientRelationshipPartner)
_IEFormElementSetValue($ClientReferringPartnerID, $ClientReferringPartner)


Sleep(4000)
MouseWheel($MOUSE_WHEEL_down, 10)

Sleep(3000)

$DropdownBusinessSectorCodeID = _IEGetObjById($oIE, "Client_BusinessSectorCode")
$DropdownBusinessSectorCodeSelect = _IETagNameGetCollection($DropdownBusinessSectorCodeID, "select", 1)
$DropdownBusinessSectorCodeSelect.focus
   If @error Then
      ConsoleWrite(@CRLF & "Can't focus drop down for Business Sector Code")

   EndIf

_IEFormElementOptionSelect($DropdownBusinessSectorCodeSelect, "Accountants (CACC)", 1, "byText")
   If @error Then
      ConsoleWrite(@CRLF & "Can't change drop down for Business Sector Code")

   EndIf

 ;/****************************Test Input has been correct  boxes *********************************************/

   Check_A_Field_Contains_In_InternetExplorer($ClientNameID, $ClientName, "Ensure $ClientName: " & $ClientName & " has been input")
   Check_A_Field_Contains_In_InternetExplorer($ClientRegOffice1ID, $ClientRegOffice1 , "Ensure Client name field is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientRegOffice2ID, $ClientRegOffice2, "Ensure billing timekeeper field is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientRegOfficeCityID, $ClientRegOfficeCity, "Ensure Date field is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientRegOffficeStateID, $ClientRegOffficeState, "Ensure Client Balance field is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientRegOfficePostCodeID, $ClientRegOfficePostCode, "Ensure Client Balance at first email field is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientContact1ID, $ClientContact1, "Ensure Outstanding Invoice Amount field is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientContactPhoneNoID, $ClientContactPhoneNo, "Ensure Previous Letter Date is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientRelationshipPartnerID, $ClientRelationshipPartner, "Ensure Previous General Note is returning data for the matter searched")
   Check_A_Field_Contains_In_InternetExplorer($ClientReferringPartnerID, $ClientReferringPartner, "Ensure Previous General Note is returning data for the matter searched")


;/****************************End*************************************************************/




EndFunc

 ;/********************************************************************************************/
 ;/****************************End*************************************************************/
 ;/********************************************************************************************/

 

Edited by CaptainBeardsEyesBeard
Link to comment
Share on other sites

I just added some error checking on the drop down to see if it's an object but it's not an object 

Console output

$DropdownBusinessSectorCodeSelect isn't an object.--> IE.au3 T3.0-2 Error from function _IEFormElementOptionSelect, $_IESTATUS_InvalidDataType

Can't change drop down for Business Sector Code

Additional error checking 

$DropdownBusinessSectorCodeID = _IEGetObjById($oIE, "Client_BusinessSectorCode")

$DropdownBusinessSectorCodeSelect = _IETagNameGetCollection($DropdownBusinessSectorCodeID, "select", 0)
         if IsObj($DropdownBusinessSectorCodeSelect) Then
         $DropdownBusinessSectorCodeSelect.focus
               If @error Then
                        ConsoleWrite(@CRLF & "Can't focus drop down for Business Sector Code")

                EndIf
         Else
            ConsoleWrite(@CRLF & "$DropdownBusinessSectorCodeSelect isn't an object.")
         Endif

_IEFormElementOptionSelect($DropdownBusinessSectorCodeSelect, "Accountants (CACC)", 0, "byText")
         If @error Then
            ConsoleWrite(@CRLF & "Can't change drop down for Business Sector Code")

         EndIf

So I'm a bit stuck it's not a object. 

I'm guessing it's going back to the issue on IEAttach (this fucntion is my nightmare). 

 

😞

Link to comment
Share on other sites

Normally a select tag is followed by option tags.  This is the tags you want to choose from.  To test different cases, I use the code from _IE_Example so I can modify the html as I want.  Here what I tested :

Func Test5()
  Local $oIE = _IE_ExampleEX("form")
  Local $oObj = _IEGetObjById($oIE, "selectExampleID")
  If Not IsObj($oObj) Then Return MsgBox($MB_SYSTEMMODAL, "", "Not an object")
  Local $colOpt = _IETagNameGetCollection($oObj, "option")
  MsgBox($MB_SYSTEMMODAL, "", $colOpt.length)
  Local $oOption = _IETagNameGetCollection($oObj, "select", 0)
  If Not IsObj($oOption) Then MsgBox($MB_SYSTEMMODAL, "", "not OK")
  ConsoleWrite (_IEFormElementOptionSelect ($oObj, 2, 1, "byIndex") & @CRLF)
EndFunc   ;==>Test5

As expected (same with you) I get "not OK" because the object cannot get itself, but I get 3 options and selection is made correctly. 

The html code is :

$sHTML &= '<select name="selectExample" id="selectExampleID">' & @CR
      $sHTML &= '<option value="homepage.html">Homepage' & @CR
      $sHTML &= '<option value="midipage.html">Midipage' & @CR
      $sHTML &= '<option value="freepage.html">Freepage' & @CR
      $sHTML &= '</select>' & @CR

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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