Forum Discussion

mesg2anil's avatar
mesg2anil
Regular Contributor
15 years ago

Dropdown list not getting updated while inputting the data from excel

Sub adprty1


Dim iexplore


Dim w5


Dim p


Dim xlSheet


Delay 3000


  Set iexplore = Sys.Process("iexplore", 2).Page("http://qaserver/Default.asp").document.frames.Frame("mainFrame").document.all


  iexplore.Item("btnAddProperty").click


  Delay 3000


 


  Log.message("You clicked on Add Property button...!")


Dim str, arrStr


  str = ReadDataFromExcel()


  arrStr = Split(str,":")


  iexplore.Item("textPropName").Value = arrStr(0)


  iexplore.Item("PropertyCode").Value = arrStr(1) 


  iexplore.Item("textareaPlotAddress").Value = arrStr(2)


  iexplore.Item("cboCertifyingCompany").ClickItem = arrStr(3)this is dropdown list which is not getting udpated


 

 iexplore.Item("textPinCode").value = arrStr(4)


  iexplore.Item("cboCountries").ClickItem = arrStr(5) this is dropdown list which is not getting udpated


End Sub


 


Function ReadDataFromExcel()


  Set Excel = Sys.OleObject("Excel.Application")


  Call Excel.Workbooks.Open("E:\Anil-Backup\Test Complete\Projects_Old\Codding\Excel Files\Login_details.xls")


  Delay 1000


  log.Message(Excel)


   For i = 1 to 2


  s = ""


    For j = 1 to 6


  s = s + VarToString(Excel.Cells(i, j)) + Chr(13) + Chr(10) + ":"


    Next


      Log.Message "Row: " + VarToString(i), s


    Next


  ReadDataFromExcel = s


 


'Closes the driver


  Call Excel.Workbooks.Close


End Function



Please help me on how to update the dropdown field?



Regards,

Anil

5 Replies

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi, Anil.


    As far as I understand, you are trying to update the value of the drop-down list using the ClickItem method, right?

    If so, the problem is caused by the fact that you used this method incorrectly as the method must be called using the following syntax: TestObj.ClickItem(Item_Name).

    In other words, replace the following two lines of your code:



    iexplore.Item("cboCertifyingCompany").ClickItem = arrStr(3) ‘this is dropdown list which is not getting updated

    ‘ ...

    iexplore.Item("cboCountries").ClickItem = arrStr(5) ‘this is dropdown list which is not getting updated


    with these ones:



    iexplore.Item("cboCertifyingCompany").ClickItem(arrStr(3))

    ' ...

    iexplore.Item("cboCountries").ClickItem(arrStr(5))


    Does this help?

  • mesg2anil's avatar
    mesg2anil
    Regular Contributor
    Hi Irina,



    Thank you for quick reply.

    I replaced the codes you suggested, but looks like its not working...

    Below is the error message I'm getting...



    The combo box item 'In4V' not found. 12:11:48 Normal  



    In4V is the value i'm trying to pass through arrStr(3) from excel to application

    samething if I do it without using arrStr(3), i.e. manual insertion using below code

    'iexplore.Item("cboCertifyingCompany").ClickItem("In4V")



    drop-down is getting updated correctly



    but if I use the below code

    iexplore.Item("cboCertifyingCompany").ClickItem(arrStr(3))          'it is not working :(



    Please suggest!!



    Regards,

    Anil

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi, Anil.


    I've reproduced the behavior you described, and as far as I can see, it is caused by the fact that an array element you are trying to use as the needed drop-down list item (for example, the arrStr(3) item) contains a non-printable character at the end. In fact, you add this character manually in your code in the ReadDataFromExcel function:



    Function ReadDataFromExcel()


      Set Excel = Sys.OleObject("Excel.Application")


      Call Excel.Workbooks.Open("E:\Anil-Backup\Test Complete\Projects_Old\Codding\Excel Files\Login_details.xls")


      Delay 1000


      log.Message(Excel)


       For i = 1 to 2


      s = ""


        For j = 1 to 6


      s = s + VarToString(Excel.Cells(i, j)) + Chr(13) + Chr(10) + ":"   ‘<= Right here


        Next


          Log.Message "Row: " + VarToString(i), s


        Next


      ReadDataFromExcel = s


     


    'Closes the driver


      Call Excel.Workbooks.Close


    End Function



    Is it necessary to add it to the generated string?


    In truth, when I removed this code segment from the ReadDataFromExcel function, everything started working fine.

    So, if it is not based on a principle, I suggest that you use the following code:



    Sub adprty1


    Dim iexplore


    Dim w5


    Dim p


    Dim xlSheet


    Delay 3000


      Set iexplore = Sys.Process("iexplore", 2).Page("http://qaserver/Default.asp").document.frames.Frame("mainFrame").document.all


      iexplore.Item("btnAddProperty").click


      Delay 3000


     


      Log.message("You clicked on Add Property button...!")


    Dim str, arrStr


      str = ReadDataFromExcel()


      arrStr = Split(str,":")


      iexplore.Item("textPropName").Value = arrStr(0)


      iexplore.Item("PropertyCode").Value = arrStr(1) 


      iexplore.Item("textareaPlotAddress").Value = arrStr(2)


      iexplore.Item("cboCertifyingCompany").ClickItem(arrStr(3)) ‘<= recommendations from my previous post


      iexplore.Item("textPinCode").value = arrStr(4)


      iexplore.Item("cboCountries").ClickItem(arrStr(5)) ‘<=recommendations from my previous post


    End Sub


     


    Function ReadDataFromExcel()


      Set Excel = Sys.OleObject("Excel.Application")


      Call Excel.Workbooks.Open("E:\Anil-Backup\Test Complete\Projects_Old\Codding\Excel Files\Login_details.xls")


      Delay 1000


      log.Message(Excel)


       For i = 1 to 2


      s = ""


        For j = 1 to 6


      s = s + VarToString(Excel.Cells(i, j)) + ":"   ‘<= recommendations from this post


        Next


          Log.Message "Row: " + VarToString(i), s


        Next


      ReadDataFromExcel = s


     


    'Closes the driver


      Call Excel.Workbooks.Close


    End Function



    Does it work now?