How to get texts in ListBox using AutoIt - autoit

I am using AutoIt to create an auto-install application. There is an dialog which contains a ListBox control, and in the listbox there are some choices for user (the detailed choices depends on user's machine. For some users there maybe only one choice, for some users there may be three choices, etc.), so I want to get the texts in the listbox to make the decision. I have tried the following code, but it did not work.
; 2223 is the ID of listbox
$txt = ControlGetText("Select Web Site", "", "[ID:2223]")
Msgbox(0, "", $txt)
After execution $txt is null.
So what should I do to get the texts in Listbox?
Here is the attribute of the listbox monitored by AutoIt v3 Window Info:
Class: WindowsForms10.Listbox.app.0.33c0d9d

I've found the 'Send' command to be unreliable on occasion, particularly if the PC is locked.
'ControlSend' has always worked to get the keystrokes where I want them.

I wrote a test to check to see if an item was in a combo box. There might be similar functions for list boxes using GuiComboBox.au3.
Func DoesItemExistInComboBox($windowtitle, $windowtext, $comboboxcontrol, $itemtocheck)
$returnvalue = 0
$ComboBoxHandle = ControlGetHandle($windowtitle, $windowtext, $comboboxcontrol)
$ComboBoxArray = _GUICtrlComboBox_GetListArray($ComboBoxHandle)
For $i = 0 TO UBound($ComboBoxArray)-1
If $ComboBoxArray[$i] = $itemtocheck Then
$returnvalue = 1
EndIf
Next
return $returnvalue
EndFunc

What about:
ControlCommand("My GUI", "", "[CLASS:ListBox; INSTANCE:1]", "SelectString", "item2")

What I want to do is to select one of the items named "Default Web Site" in the list, but it seems that the list content can not be got, so finally I tried another way:
At first I make the listbox focused, and then I choose the item "Default Web Site" by sending "Def":
ControlFocus($Title, "", "[NAME:lbWebSites]")
; Select the option "Default Web Site", so press "def" to set the desired item.
Send("Def")

Related

How to check that the window close button is pressed [x]

$variable = MsgBox(0, "", "Return value.")
MsgBox(0, "", $variable)
; Always returns 1
Is it possible to do this in the simplest way without using
Win* functions,
Au3Info
As you are using the $MB_OK flag, the MsgBox is considered as "for info only" and Window does not distinguish between the various actions. If you look at the returns from MsgBoxes with multiple buttons, you usually find that the [X] returns the same value as the "Cancel" button.
If you really want to distinguish when the user closes the dialog with the [X], try the ExtMsgBox UDF (https://www.autoitscript.com/forum/topic/109096-extended-message-box-new-version-19-nov-21/) - that does give a unique return.

ControlID changes each time a window is launched

Consider this AutoIt code:
WinActivate("Test Window")
Sleep(5000)
ControlClick("Test Window", "", 197128)
There is a button in the window I am testing. I have written a simple script to click on the button using ControlClick. I use controlID to identify and click on the button (I use AutoIt window Info to get the controlID). The script works. The problem is that the control ID changes each time the test window is launched. As a result, the script does not simulate a button click each time a new instance of the window is launched. How can I make controlclick work as expected every time?
For controls that have dynamic control Ids, the best is to use advanced detection.
As it can be seen in the Help File:
A special description can be used as the controlID parameter used in most of the
Control...() functions. This description can be used to identify a control by the
following properties:
For example,
ControlSend("Untitled - Notepad", "", "[CLASS:Edit; INSTANCE:1]", "This is some text")
Or
ControlClick("My Window", "", "[CLASS:Button; TEXT:Finish; INSTANCE:2]")
Don't forget to set:
Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

Focus change on control Autoit

I have a application window with two text fields (no access to the application code, so cant change anything). User scans a barcode in the fields, the action "enter press" is programmed in the scanner and cannot be changed. I need to validate the fields before enter is pressed, I can validate the first field but the issue is I need to validate the second field before enter is press(which is through the scanner). Is there a way this can be achieved using AutoIT? I hope the question make sense.
Use the "AutoIt v2 Window Info" tool (Au3Info.exe) to identify the two edit controls. On the "Control" tab you find the "Advanced Mode", which will show data like "[CLASS:Edit;INSTANCE:2]". Now use this information to read the data of the control:
$Text1 = ControlGetText('window title', '', '[CLASS:Edit; INSTANCE:1]')
$Text2 = ControlGetText('window title', '', '[CLASS:Edit; INSTANCE:2]')
See the example here: http://www.autoitscript.com/autoit3/docs/functions/ControlGetText.htm
most barcode scanners can be programmed to not send the terminator (enter) usually by scanning a couple special barcodes in the users manual
I program scanners with special terminators so our program can tell the input was from a scanner and not key presses

What is the most efficient way of filling in details on a web form?

Take a standard web page with lots of text fields, drop downs etc.
What is the most efficient way in webdriver to fill out the values and then verify if the values have been entered correctly.
You only have to test that the values are entered correctly if you have some javascript validation or other magic happening at your input fields. You don't want to test that webdriver/selenium works correctly.
There are various ways, depending if you want to use webdriver or selenium. Here is a potpourri of the stuff I'm using.
Assert.assertEquals("input field must be empty", "", selenium.getValue("name=model.query"));
driver.findElement(By.name("model.query")).sendKeys("Testinput");
//here you have to wait for javascript to finish. E.g wait for a css Class or id to appear
Assert.assertEquals("Testinput", selenium.getValue("name=model.query"));
With webdriver only:
WebElement inputElement = driver.findElement(By.id("input_field_1"));
inputElement.clear();
inputElement.sendKeys("12");
//here you have to wait for javascript to finish. E.g wait for a css Class or id to appear
Assert.assertEquals("12", inputElement.getAttribute("value"));
Hopefully, the results of filling out your form are visible to the user in some manner. So you could think along these BDD-esque lines:
When I create a new movie
Then I should see my movie page
That is, your "new movie" steps would do the field entry & submit. And your "Then" would assert that the movie shows up with your entered data.
element = driver.find_element(:id, "movie_title")
element.send_keys 'The Good, the Bad, the Ugly'
# etc.
driver.find_element(:id, "submit").click
I'm just dabbling in this now, but this is what I came up with so far. It certainly seems more verbose than something like Capybara:
fill_in 'movie_title', :with => 'The Good, the Bad, the Ugly'
Hope this helps.

How can I trap "View Report" in ReportViewer (webforms) for SSRS?

I am using ReportViewer.WebForms in asp.net page. I have the parameter toolbar showing up where I can select a parameter, it does a postback to get the next parameter (dependent on the first), and so forth.
When I click the View Report button there is a postback and the report will display fine.
All this works great.
What I would like to do is set the ShowReportBody to false
ReportViewer.ShowReportBody = False
At this point I would like to grab all the parameters that have been selected by the user and run the render method to export to a file (of my choosing .. maybe excel, maybe pdf .. does not really matter, nor is the topic of this question).
So, my question is, how (or can I) trap the button event of the View Report button? I would like to be able to use the ReportViewer UI in order to capture all the parameters instead of building custom parameters.
I'd also like to rename this, but, again .. another topic :)
You can use the IsPostBack flag and QueryString
Example:
Viewer.ShowReportBody = false
if(IsPostBack)
{
if(Request.QueryString["Exec"] = "Auto")
Viewer.ShowReportBody = true;
...
}
else
{
Viewer.ShowReportBody = true;
}

Resources