1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . Collections . ObjectModel ;
3
4
using System . Data ;
4
5
using System . Drawing ;
5
6
using System . Linq ;
@@ -64,9 +65,10 @@ public class SeleniumBrowserElementActionCommand : ScriptCommand
64
65
[ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Get Attribute" ) ]
65
66
[ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Get Matching Elements" ) ]
66
67
[ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Wait For Element To Exist" ) ]
67
- [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Switch to frame" ) ]
68
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Switch to frame" ) ]
69
+ [ Attributes . PropertyAttributes . PropertyUISelectionOption ( "Get Count" ) ]
68
70
[ Attributes . PropertyAttributes . InputSpecification ( "Select the appropriate corresponding action to take once the element has been located" ) ]
69
- [ Attributes . PropertyAttributes . SampleUsage ( "Select from **Invoke Click**, **Left Click**, **Right Click**, **Middle Click**, **Double Left Click**, **Clear Element**, **Set Text**, **Get Text**, **Get Attribute**, **Wait For Element To Exist**" ) ]
71
+ [ Attributes . PropertyAttributes . SampleUsage ( "Select from **Invoke Click**, **Left Click**, **Right Click**, **Middle Click**, **Double Left Click**, **Clear Element**, **Set Text**, **Get Text**, **Get Attribute**, **Wait For Element To Exist**, **Get Count** " ) ]
70
72
[ Attributes . PropertyAttributes . Remarks ( "Selecting this field changes the parameters that will be required in the next step" ) ]
71
73
public string v_SeleniumElementAction { get ; set ; }
72
74
[ XmlElement ]
@@ -225,7 +227,7 @@ where rw.Field<string>("Parameter Name") == "Clear Element Before Setting Text"
225
227
clearElement = "No" ;
226
228
}
227
229
228
- if ( clearElement . ToLower ( ) == "yes" )
230
+ if ( clearElement . ToLower ( ) == "yes" )
229
231
{
230
232
element . Clear ( ) ;
231
233
}
@@ -260,7 +262,8 @@ where rw.Field<string>("Parameter Name") == "Clear Element Before Setting Text"
260
262
break ;
261
263
262
264
case "Get Text" :
263
- case "Get Attribute" :
265
+ case "Get Attribute" :
266
+ case "Get Count" :
264
267
265
268
string VariableName = ( from rw in v_WebActionParameterTable . AsEnumerable ( )
266
269
where rw . Field < string > ( "Parameter Name" ) == "Variable Name"
@@ -274,6 +277,12 @@ where rw.Field<string>("Parameter Name") == "Attribute Name"
274
277
if ( v_SeleniumElementAction == "Get Text" )
275
278
{
276
279
elementValue = element . Text ;
280
+ }
281
+ else if ( v_SeleniumElementAction == "Get Count" )
282
+ {
283
+ elementValue = "1" ;
284
+ if ( element is ReadOnlyCollection < IWebElement > )
285
+ elementValue = ( ( ReadOnlyCollection < IWebElement > ) element ) . Count ( ) . ToString ( ) ;
277
286
}
278
287
else
279
288
{
@@ -443,7 +452,7 @@ public override List<Control> Render(frmCommandEditor editor)
443
452
RenderedControls . Add ( CommandControls . CreateDefaultLabelFor ( "v_SeleniumElementAction" , this ) ) ;
444
453
RenderedControls . AddRange ( CommandControls . CreateUIHelpersFor ( "v_SeleniumElementAction" , this , new Control [ ] { ElementActionDropdown } , editor ) ) ;
445
454
ElementActionDropdown . SelectionChangeCommitted += seleniumAction_SelectionChangeCommitted ;
446
-
455
+
447
456
RenderedControls . Add ( ElementActionDropdown ) ;
448
457
449
458
ElementParameterControls = new List < Control > ( ) ;
@@ -526,7 +535,8 @@ public void seleniumAction_SelectionChangeCommitted(object sender, EventArgs e)
526
535
break ;
527
536
528
537
case "Get Text" :
529
- case "Get Matching Elements" :
538
+ case "Get Matching Elements" :
539
+ case "Get Count" :
530
540
foreach ( var ctrl in ElementParameterControls )
531
541
{
532
542
ctrl . Show ( ) ;
0 commit comments