Sign in to follow this  
Followers 0
kudrow

Copy Text From Drop Down Menu

10 posts in this topic

Hey Everyone,

The script I am working on simply copies text from fields in a third party application. So basically my script tabs thru the fields and copies and pastes the data into a text file. I am finding that I can not simply copy the data from a drop down menu unless it is editable. If it has static data I can not select, ctrl+c. I hope I have explained what I am trying to do well enough. 

Thanks,

Cody

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use controlgettext for your inputs (much better than copying to the buffer)

Use the _GUICtrlMenu_* functions to loop through your menu items, and use: _GUICtrlMenu_GetItemText to get the text.

the _guictrlmenu will require HWND's to function, which you can grab from controlgethandle.

Helpfile them all to figure them out.

On second thought, i bet your 'menu' is a combobox, so you should use the _GuiCtrlComboBox_* functions.

Use the AutoIT window info tool to find the class of the control

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I appreciate the fast response. I just want to make sure I understand you as well as you understand me. The gui I am trying to read from is not my script. I have no control over it. It is an input form from another application that when ran is already populated with information. Below is a copy of my script.

#include <Clipboard.au3>
Sleep (5000)
Local $file = FileOpen("test.txt", 2)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
 EndIf
 ;========================================================
 ; Copy First Name
Send ("{TAB 13}")
Send ("^c") 
$text = _ClipBoard_GetData()
FileWrite ( $file, "$first="&$text&@CRLF)
;=========================================================
; Copy Last Name
Send ("{TAB}")
Send ("^c") 
$text2 = _ClipBoard_GetData()
if $text2==$text Then
   FileWrite ($file, "$last="&@CRLF)
   Else
      FileWrite ($file, "$last="&$text2&@CRLF)
   EndIf
;==========================================================
; Copy Middle Initial
Send ("{TAB}")
Send ("^c") 
$text3 = _ClipBoard_GetData()
if $text3==$text2 Then
   FileWrite ($file, "$midIn="&@CRLF)
   Else
      FileWrite ($file, "$midIn="&$text3&@CRLF)
   EndIf
;==========================================================
; Copy Address 1
Send ("{TAB 6}")
Send ("^c") 
$text4 = _ClipBoard_GetData()
If $text4==$text3 Then
   FileWrite ($file, "$address1="&@CRLF)
   Else
      FileWrite ($file, "$address1="&$text4&@CRLF)
   EndIf
;==========================================================
; Copy Address 2
Send ("{TAB}")
Send ("^c") 
$text5 = _ClipBoard_GetData()
if $text5==$text4 Then
   FileWrite ($file, "$address2="&@CRLF)
   Else
      FileWrite ($file, "$address2="&$text5&@CRLF)
   EndIf
;==========================================================
; Copy City
Send ("{TAB}")
Send ("^c") 
$text6 = _ClipBoard_GetData()
if $text6==$text5 Then
   FileWrite ($file, "$city="&@CRLF)
   Else
      FileWrite ($file, "$city="&$text6&@CRLF)
   EndIf
;==========================================================
; Copy State
Send ("{TAB}")
Send ("^c") 
$text7 = _ClipBoard_GetData()
if $text7==$text6 Then
   FileWrite ($file, "$state="&@CRLF)
   Else
      FileWrite ($file, "$state="&$text7&@CRLF)
   EndIf

FileClose($file)

Thanks again for the help.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Understood, and you should look into the functions I suggested.

There is no telling if your application will pick up all your tab's to correctly focus on the proper control.  The control* functions make certain, and the controlgettext will be a certain way, to grab the text you need.

In general, sends are not reliable, and I'd suggest to avoid them.

If your application is web based, you would need to use the _ie functions...i can only speculate wihout more information

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Understood, and you should look into the functions I suggested.

There is no telling if your application will pick up all your tab's to correctly focus on the proper control.  The control* functions make certain, and the controlgettext will be a certain way, to grab the text you need.

In general, sends are not reliable, and I'd suggest to avoid them.

If your application is web based, you would need to use the _ie functions...i can only speculate wihout more information

Perfect, I appreciate the confirmation of understanding. I will look into your suggestions now. It is not web based. Thanks again!

Share this post


Link to post
Share on other sites

OK I have been trying to figure this out. Below is a picture of the info for the dropdown menu. I am not sure what I need to put into the following script for the text to show up. Any help is greatly appreciated.

post-75726-0-50478600-1382125645_thumb.j

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>

Sleep (5000)
$hWnd="[CLASS:ThunderRT6ComboBox; INSTANCE:14]"
Local $text = _GUICtrlComboBox_GetCurSel($hWnd)
MsgBox(0, "Text read was:", $text)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ouch, that's not a standard control.  I doubt the _guictrlcombobox* functions would work.

standard:

>>>> Control <<<<
Class: ComboBox
Instance: 1
ClassnameNN: ComboBox1
Name: 
Advanced (Class): [CLASS:ComboBox; INSTANCE:1]
ID: 2444
Text: 

Maybe someone else can add some suggestions.  BTW, if yours were standard, you would have to do it like this:

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>

Sleep (5000)
$sControlIdentifier="[CLASS:ThunderRT6ComboBox; INSTANCE:14]"
$hContorl = ControlGetHandle("YourControlsWindowTitle","",$sControlIdentifier)
Local $text = _GUICtrlComboBox_GetCurSel($hContorl)
MsgBox(0, "Text read was:", $text)

Another suggestion, ID's are generally stale, where instance can change depending on user rights (as an example)...also, instances can change if new controls of the same class are added, so I would change it to:

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>

Sleep (5000)
$sControlIdentifier= 131
$hContorl = ControlGetHandle("YourControlsWindowTitle","",$sControlIdentifier)
Local $text = _GUICtrlComboBox_GetCurSel($hContorl)
MsgBox(0, "Text read was:", $text)
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Yeah both yours and my code return 0. I appreciate the help though. I will see if anyone else has any suggestions.

Thanks again!

Share this post


Link to post
Share on other sites

OK so the second script you wrote works some what. It actually returns a number instead of the text. The number looks like an index reference. 0 being the first item in the list. I wonder why it will not tell me the actual text thought.

Share this post


Link to post
Share on other sites

I GOT IT!!!! Modifying your code a little I am able to get the full text using the index number.

#include <GuiMenu.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>


Sleep (5000)
$winname= WinGetTitle("[active]")
$sControlIdentifier= 131
$hContorl = ControlGetHandle($winname,"",$sControlIdentifier)
Local $text = _GUICtrlComboBox_GetCurSel($hContorl)
$text2=""
_GUICtrlComboBox_GetLBText ($hContorl, $text, $text2)
MsgBox(0, "Text read was:", $text2)

Share this post


Link to post
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
Sign in to follow this  
Followers 0