Jump to content

Combobox Item Selection Not working


Recommended Posts

Hello People, I am new to autoIt and I am asked to automate one of our project which is a windows application. I have tried , explored and worked on a scenario. I have problem with selecting a ComboBox and once clicked on 'ok' button, it should go to the next stage. Initially the same code was working fine, but now it's not.I am not getting what exactly the problem is. It would be a great great help if anyone of you could help me resolve this issue please. Attaching the code here:-  

#include<IE.au3>
#Include <GuiTreeView.au3>
Global Const $CB_SETCURSEL = 0x14E

WinActivate ( "Customer Care Portal Phase-2 - Internet Explorer","")
Sleep(2000)


;CSR Team Information Combo box
WinActivate("CSR Team Information","")
;ControlClick("CSR Team Information", "", "[CLASS:ThunderRT6ComboBox ; INSTANCE:1]")
Sleep ( 3000 )
$h_combobox = ControlGetHandle("CSR Team Information", "", "[CLASS:ThunderRT6ComboBox ; INSTANCE:1]")
$i_index = 2
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int",0)

ControlClick("CSR Team Information","","[CLASS:ThunderRT6CommandButton; INSTANCE:1]")  ;Clicks on Ok button

Sleep(1000)
;New Contact Window
WinActivate ("New Contact","")
ControlClick("Customer Care Portal Phase-2 - Internet Explorer", "","[CLASS:ThunderRT6CommandButton ; INSTANCE:16]")  ;Clicks on New contact button

Sleep(3000)
ControlSetText ( "New Contact", "", "[CLASS:ThunderRT6TextBox; INSTANCE:6]", "H30098556")  ;Enters value in textBox for for Inquired About
Sleep(2000)
ControlSetText ( "New Contact", "", "[CLASS:ThunderRT6TextBox; INSTANCE:5]", "H30098556")    ;Enters value in textBox for for Inquired For
Sleep ( 2000)

;Contact Type Combo box

$h_combobox = ControlGetHandle("New Contact", "", "[CLASS:ThunderRT6ComboBox; INSTANCE:9]")
$i_index = 3  ; Correspondance
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int", 0)
Sleep ( 2000 )

;Inquiry Type Combo box

$h_combobox = ControlGetHandle("New Contact", "","[CLASS:ThunderRT6ComboBox; INSTANCE:1]")
$i_index = 4  ; CUSTOMER INQUIRY
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int", 0)
Sleep ( 2000 )

ControlClick("New Contact","", "[CLASS:ThunderRT6CommandButton; INSTANCE:5]") ; Clicks on View Button

;ControlClick("New Contact","", "[CLASS:ThunderRT6CommandButton; INSTANCE:4]")    ;Clicks on Create Inquiry

WinClose("New Contact", "")

Link to comment
Share on other sites

No Francesco. Once the Combo Box is opened, it directly clicks on "Ok"  , item in the Combo Box is not selected.  I guess problem is with below section of code.

CSR Team Information Combo box
WinActivate("CSR Team Information","")
;ControlClick("CSR Team Information", "", "[CLASS:ThunderRT6ComboBox ; INSTANCE:1]")
Sleep ( 3000 )
$h_combobox = ControlGetHandle("CSR Team Information", "", "[CLASS:ThunderRT6ComboBox ; INSTANCE:1]")
$i_index = 2
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int",0)

ControlClick("CSR Team Information","","[CLASS:ThunderRT6CommandButton; INSTANCE:1]")  ;Clicks on Ok button

Edited by ShrutiW
Link to comment
Share on other sites

@ShrutiW
Debug a little bit your code.
Try to do this with each of the function you use (so you can see where your script stops to work):

If WinActivate() Then
    ConsoleWrite("WinActivate OK!" & @CRLF)
    ; Other instructions
Else
    ConsoleWrite("WinActivate ERR: " & @error & @CRLF) ; If @error is set by the function
EndIf

And, this line of code

16 minutes ago, ShrutiW said:

DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int",0)

Could be easily replaced with the function _GUICtrlComboBox_GetCurSel() :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Hey @FrancescoDiMuro, I tried replacing DlCall function with  _GUICtrlComboBox_GetCurSel() , But how Can I get the index of the exact element , i.e. Suppose if I want to select an item in the 2nd index, where should I mention it in that function? I have seen the syntax but I can't see any place to put Index of the item in Combo Box. 

Edited by ShrutiW
Link to comment
Share on other sites

@FrancescoDiMuro  I have made changes as per your recommendations, still it is not running. 

;CSR Team Information Combo box
WinActivate("CSR Team Information","")
Sleep ( 3000 )
 _GUICtrlComboBox_SetCurSel("[CLASS:ThunderRT6ComboBox ; INSTANCE:1]", 3)
ControlClick("CSR Team Information","","[CLASS:ThunderRT6CommandButton; INSTANCE:1]")          ;Clicks on Ok button
 

Could you please suggest What changes should I make in the above script?😞

Link to comment
Share on other sites

@ShrutiW

Ok, so, of the window is activated, you can debug the next lines of your script.

In this case, you can do something like:

#include <GuiComboBox.au3>
#include <MsgBoxConstants.au3>

Global $hdlComboBox = ControlGetHandle(AddWindowTitle, "", AddWindowControlInformation) ; Change title and control information here
If IsHWnd($hdlComboBox) Then
    If _GUICtrlComboBox_SetCurSel($hdlComboBox, 3) <> -1 Then
        MsgBox($MB_ICONINFORMATION, "", "The ComboBox item #3 has been selected.")
    Else
        MsgBox($MB_ICONERROR, "", "Error during the selection of the ComboBox item.")
    EndIf
Else
    MsgBox($MB_ICONERROR, "", "Cannot obtain the handle of the ComboBox control." & @CRLF & "Error: " & @error)
EndIf

Meanwhile, could you please post the AutoItWindowInfoTool summary? :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Yes . I tried. And it is showing the msgBox that 

"The ComboBox item #3 has been selected.".

Then It clicks on "OK" button, and same thing is happening again. 😥 What does that indicate? I'm I missing something in code? 

This is how it shows:

image.png.1a84fcf5be4a4540c1ea7d2923304f77.png

Link to comment
Share on other sites

Hi @FrancescoDiMuro  Can you Please have a look on this code and suggest me required changes ? I tried it but no success yet. 

#include<IE.au3>
#Include <GuiTreeView.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
;#AutoIt3Wrapper_Run_Debug=y
;Global Const $CB_SETCURSEL = 0x14E
;_GUICtrlComboBox_SetCurSel ( "[CLASS:ThunderRT6ComboBox ; INSTANCE:1]", -1)


WinActivate ( "Customer Care Portal Phase-2 - Internet Explorer","")
Sleep(2000)

;CSR Team Information Combo box
WinActivate("CSR Team Information","")
Sleep ( 3000 )
;GUICtrlComboBox_SetCurSel("[CLASS:ThunderRT6ComboBox ; INSTANCE:1]", 3)
ControlCommand("CSR Team Information", "", "SelectString", 'Open Work Items: 000000061 | Green Bay/CCP IT/CCP IT Support Team')
Global $hdlComboBox = ControlGetHandle("CSR Team Information", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]")
If IsHWnd($hdlComboBox) Then
    If _GUICtrlComboBox_SetCurSel($hdlComboBox, 3)<> -1 Then
        MsgBox($MB_ICONINFORMATION, "", "The ComboBox item #3 has been selected.")
    Else
        MsgBox($MB_ICONERROR, "", "Error during the selection of the ComboBox item.")
    EndIf
Else
    MsgBox($MB_ICONERROR, "", "Cannot obtain the handle of the ComboBox control." & @CRLF & "Error: " & @error)
 EndIf

ControlClick("CSR Team Information","","[CLASS:ThunderRT6CommandButton; INSTANCE:1]")  ;Clicks on Ok button




Sleep(1000)
;New Contact Window
WinActivate ("New Contact","")
ControlClick("Customer Care Portal Phase-2 - Internet Explorer", "","[CLASS:ThunderRT6CommandButton ; INSTANCE:16]")  ;Clicks on New contact button

Sleep(3000)
ControlSetText ( "New Contact", "", "[CLASS:ThunderRT6TextBox; INSTANCE:6]", "H30098556")  ;Enters value in textBox for for Inquired About
Sleep(2000)
ControlSetText ( "New Contact", "", "[CLASS:ThunderRT6TextBox; INSTANCE:5]", "H30098556")    ;Enters value in textBox for for Inquired For
Sleep ( 2000)

;Contact Type Combo box

$h_combobox = ControlGetHandle("New Contact", "", "[CLASS:ThunderRT6ComboBox; INSTANCE:9]")
$i_index = 3  ; Correspondance
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int", 0)
Sleep ( 2000 )

;Inquiry Type Combo box

$h_combobox = ControlGetHandle("New Contact", "","[CLASS:ThunderRT6ComboBox; INSTANCE:1]")
$i_index = 4  ; CUSTOMER INQUIRY
DllCall("user32.dll", "int", "SendMessage", "hwnd", $h_combobox, "int", $CB_SETCURSEL, "int", $i_index, "int", 0)
Sleep ( 2000 )



ControlClick("New Contact","", "[CLASS:ThunderRT6CommandButton; INSTANCE:5]") ; Clicks on View Button

 

LoginCCP1.au3

Link to comment
Share on other sites

@ShrutiW
Try again with this one :)

Spoiler
#include<IE.au3>
#Include <GuiTreeView.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
;#AutoIt3Wrapper_Run_Debug=y
;Global Const $CB_SETCURSEL = 0x14E
;_GUICtrlComboBox_SetCurSel ( "[CLASS:ThunderRT6ComboBox ; INSTANCE:1]", -1)


WinActivate ( "Customer Care Portal Phase-2 - Internet Explorer","")
Sleep(2000)

;CSR Team Information Combo box
WinActivate("CSR Team Information","")
Sleep ( 3000 )
;GUICtrlComboBox_SetCurSel("[CLASS:ThunderRT6ComboBox ; INSTANCE:1]", 3)
Global $hdlComboBox = ControlGetHandle("CSR Team Information", "", "[CLASS:ThunderRT6CommandButton; INSTANCE:1]")
If IsHWnd($hdlComboBox) Then
    If ControlCommand("CSR Team ?Information", "", $hdlComboBox, "SelectString", 'Open Work Items: 000000061 | Green Bay/CCP IT/CCP IT Support Team') Then
        MsgBox($MB_ICONINFORMATION, "", "The ComboBox item has been set.")
    Else
        MsgBox($MB_ICONERROR, "", "Error during the setting of the ComboBox item.")
    EndIf
Else
    MsgBox($MB_ICONERROR, "", "Cannot obtain the handle of the ComboBox control." & @CRLF & "Error: " & @error)
 EndIf

ControlClick("CSR Team Information","","[CLASS:ThunderRT6CommandButton; INSTANCE:1]")  ;Clicks on Ok button




Sleep(1000)
;New Contact Window
WinActivate ("New Contact","")
ControlClick("Customer Care Portal Phase-2 - Internet Explorer", "","[CLASS:ThunderRT6CommandButton ; INSTANCE:16]")  ;Clicks on New contact button

Sleep(3000)
ControlSetText ( "New Contact", "", "[CLASS:ThunderRT6TextBox; INSTANCE:6]", "H30098556")  ;Enters value in textBox for for Inquired About
Sleep(2000)
ControlSetText ( "New Contact", "", "[CLASS:ThunderRT6TextBox; INSTANCE:5]", "H30098556")    ;Enters value in textBox for for Inquired For
Sleep ( 2000)



ControlClick("New Contact","", "[CLASS:ThunderRT6CommandButton; INSTANCE:5]") ; Clicks on View Button

 

By the way, since the Portal is running on IE, couldn't you use IE UDF to automate that?
Do you have access to the source code of the Webpage? :)
 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@FrancescoDiMuro   I tried running the script, got a msgbox saying " "Error during the setting of the ComboBox item.""

Sorry to ask so many silly questions, but How can I use IE UDF to automate it because this is a windows application ?  IE UDFs can be used when its a webpage right?  

Edited by ShrutiW
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...