Forum Discussion

kpinnisetti's avatar
kpinnisetti
Contributor
11 years ago
Solved

Selecting drop down values by keys method

Hi, Dropdowns are not recognized by test complete so i wanted to use keys method to select a particular value by its content text and by keys method. In our dropdown list we have Sales and Non Sales values. when i'm trying to execute the below query even the content text is Sales it's skipping and executing the else part. Am i missing any thing in my if statement?




Sub test


  Set clickPosCatdd = Aliases.ddEmpTermPosCat


  clickPosCatdd.Click


  If Aliases.ddEmpTermValPosCategory.innerText = "Sales" then 


    Set clickddValue = Aliases.ddEmpTermValPosCategory


     clickddValue.Keys ("[Enter]")


    log.message("Non Sales is not clicked")


  else


    Set clickddValue = Aliases.ddEmpTermValPosCategory


    clickddValue.Keys ("[Down]")


    clickddValue.Keys ("[Enter]")


    log.Message("Non Sales is clicked")


 


   


  End If

  • I would add a log message

    Log.Message Aliases.ddEmpTermValPosCategory.innerText

    to confirm that the text is actually "Sales" during the test run in case it is blank or there is something unexpected like an extra space character.



    You could also try entering the first character of the list item if that works

    clickddValue.Keys ("S") to enter sales or

    clickddValue.Keys ("N") to enter non sales

6 Replies

  • paul_scroce's avatar
    paul_scroce
    Frequent Contributor
    I would add a log message

    Log.Message Aliases.ddEmpTermValPosCategory.innerText

    to confirm that the text is actually "Sales" during the test run in case it is blank or there is something unexpected like an extra space character.



    You could also try entering the first character of the list item if that works

    clickddValue.Keys ("S") to enter sales or

    clickddValue.Keys ("N") to enter non sales
  • Thanks Paul that helps.. I will try that with log message what value it's returning during test run.
  • Paul when executing the log message script
    Log.Message Aliases.ddEmpTermValPosCategory.innerText
    it's returning SalesNon-Sales in the log files.
  • Actually now I remapped the object to the single item in the drop down, so my script is working now. thanks for your time and reply.




    Sub test Set

    clickPosCatdd = Aliases.ddEmpTermPosCat

    clickPosCatdd.Click

    If Aliases.ddEmpTermValPosCategory.contentText = "Non-Sales" then

      Set clickddValue = Aliases.ddEmpTermValPosCategory

      clickddValue.Keys ("[Enter]")

      log.message("Sales is clicked")

    else

      Set clickddValue = Aliases.ddEmpTermValPosCategory

      clickddValue.Keys ("[Down]")

      clickddValue.Keys ("[Enter]")

      log.Message("Non Sales is clicked")

    End If

    End Sub



    • gvkr1985's avatar
      gvkr1985
      Occasional Contributor

      How to display the values selected by Dropdown....

       

      Ex: If i have 1,2,3 in the dropdown and using the code, i selected 2 : Object.Clickitem(I). Now i want to display that value..

       

      Log.Message  ?????

       

       

      Could you please help me...

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        The actual code may depend on your combo-box, but you may use this code sample as a starting idea:

          If (IsSupported(oCombo, "wText")) Then
            strValue = oCombo.wText
          ElseIf (IsSupported(oCombo, "Text")) Then
            strValue = oCombo.Text

          Else

            ...

          End If