This is a migrated thread and some comments may be shown as answers.

getting dropdownlist / checklists values

8 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ratna
Top achievements
Rank 2
Ratna asked on 23 Sep 2015, 07:57 PM

Hi!

I've been on a trial version for this week.  My initial objectives are to have some regression scripts created to do the following tasks:

1) verify list of values from dropdownlists on web portal pages

2) verify list of values with checklists / checkboxes on web portal pages

I'm working on a web portal app that have lots of dropdownlists with lots of values.  I need some assistance in getting each of the values from the dropdownlist and display it to confirm, then write into the logs or datasource and perform a comparison, returning pass/fail results.  I was able to do the following so far (in VB):

1) get the total count of the dropdownlist

Dim P_Count = Pages.MainPlaceholderDrpdwnPortFolioSelect.ChildNodes.Count.ToString()           
Log.WriteLine ("Total number of Portfolios is " +P_Count)

2) get the default selected value

Log.WriteLine (Pages.MainPlaceholderDrpdwnPortFolioSelect.SelectedOption.Text.ToString())

3) perform the comparison (only with innertex, which is pulls the whole text of combined values together)

 Dim PortfoliosRuntime = Pages.MainPlaceholderDrpdwnPortFolioSelect.InnerText 
 Dim PortfoliosList = Data("PortfoliosList").ToString() 'same as Data(0).ToString()

 If PortfoliosRuntime = PortfoliosList Then
        Log.WriteLine (PortfoliosRuntime)
        Log.Writeline ("Portfolios lists matched!")
 Else
       Throw New Exception("Portfolios lists didn't matched!")
 End If

 

I need help in the following and getting it work:

1) For-Next loop to loop through each value of the dropdownlist and confirmed in MessageBox or log

Dim i
For i=0 to P_Count-1
Log.WriteLine ("Loop count = " + i.ToString())
Next

2) get MessageBox to work and display message box for each value

Dim MsgBox As New NativeWindow()
MsgBox.AssignHandle(ActiveBrowser.Window.Handle)
MessageBox.Show(MsgBox, "This is a message!" 

I appreciate it and thanks in advance for your assistance.

Thanks,

Stephen

8 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 25 Sep 2015, 04:19 PM
Hello Stephen,

Under the cover, a standard HTML drop down select looks like this:

<select>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>

Since every item in the list is represented by an <option> tag, we can take advantage of that in code like this:

Dim options As ReadOnlyCollection(Of HtmlOption) = Pages.MainPlaceholderDrpdwnPortFolioSelect.Options
Log.WriteLine(options.Count.ToString())
 
For Each [option] As HtmlOption In options
    Log.WriteLine([option].Text + [option].Value)
 
    MessageBox.Show([option].Text + [option].Value)
Next



Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Ratna
Top achievements
Rank 2
answered on 28 Sep 2015, 04:14 PM

Hi Cody,

I got  the following error messages in the Log:

C:\Users\snguyen\Documents\Test Studio Projects\FirstSimpleTestonNexus\CSAM - Portfolios Lists (2).tstest.vb(66) : error BC30002: Type 'ReadOnlyCollection' is not defined. Dim options As ReadOnlyCollection(Of HtmlOption) = Pages.Virtus0.MainPlaceholderDrpdwnPortFolioSelect.Options

 and

C:\Users\snguyen\Documents\Test Studio Projects\FirstSimpleTestonNexus\CSAM - Portfolios Lists (2).tstest.vb(74) : error BC30451: 'MessageBox' is not declared. It may be inaccessible due to its protection level. MessageBox.Show([option].Text + [option].Value)

 Please advised.

 

 

0
Ratna
Top achievements
Rank 2
answered on 28 Sep 2015, 04:26 PM

 I'm able to get the values into log without the 'ReadOnlyCollection' included...

Dim options = Pages.Virtus0.MainPlaceholderDrpdwnPortFolioSelect.Options

0
Cody
Telerik team
answered on 28 Sep 2015, 06:46 PM
Hi,

ReadOnlyCollection is defined in the namespace System.Collections.ObjectModel. You must add an:

imports System.Collections.ObjectModel;

MessageBox is defined in the assembly System.Windows.Forms. You must add a reference to this assembly along with an:

imports System.Windows.Forms.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Ratna
Top achievements
Rank 2
answered on 28 Sep 2015, 07:29 PM

Hi Cody, 

When I put these 2 lines in the Coded Step, I got the following errors in log:

Imports System.Collections.ObjectModel
Imports System.Windows.Forms 

C:\Users\snguyen\Documents\Test Studio Projects\FirstSimpleTestonNexus\CSAM - Portfolios Lists - Working.tstest.vb: Line 59: (BC30035) Syntax error.C:\Users\snguyen\Documents\Test Studio Projects\FirstSimpleTestonNexus\CSAM - Portfolios Lists - Working.tstest.vb: Line 60: (BC30035) Syntax error.

BTW, the Imports System.Windows.Forms don't exist because when do Imports System.Windows. it only display "Input" and "Markup" as options.

 

0
Cody
Telerik team
answered on 28 Sep 2015, 08:30 PM
Hi,

Did you add a reference to the assembly System.Windows.Forms.dll as I previously explained? This is required to be able to use MessageBox. You should find this assembly in the folder C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 as shown in the attached screen shot.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Ratna
Top achievements
Rank 2
answered on 28 Sep 2015, 08:53 PM
I saw the System.Windows.Form but didn't see the System.Collections.ObjectModel, is it located somewhere else?
0
Cody
Telerik team
answered on 28 Sep 2015, 09:10 PM
Hello,

Well sort of it is. It's integrated into the .NET framework core dll, mscorlib.dll. Just by having a reference to System.dll (which you get by default and cannot NOT have this) you should be able to use the statement:

Imports System.Collections.ObjectModel

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Ratna
Top achievements
Rank 2
Answers by
Cody
Telerik team
Ratna
Top achievements
Rank 2
Share this question
or