Skip to content

Commit 7011e05

Browse files
committed
Adding support to get the count of elements with any "Element Search Method" eg: ID, Class, Tag Name or XPath
1 parent 56547c3 commit 7011e05

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

taskt/Core/Automation/Commands/SeleniumBrowserElementActionCommand.cs

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
34
using System.Data;
45
using System.Drawing;
56
using System.Linq;
@@ -64,9 +65,10 @@ public class SeleniumBrowserElementActionCommand : ScriptCommand
6465
[Attributes.PropertyAttributes.PropertyUISelectionOption("Get Attribute")]
6566
[Attributes.PropertyAttributes.PropertyUISelectionOption("Get Matching Elements")]
6667
[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")]
6870
[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**")]
7072
[Attributes.PropertyAttributes.Remarks("Selecting this field changes the parameters that will be required in the next step")]
7173
public string v_SeleniumElementAction { get; set; }
7274
[XmlElement]
@@ -225,7 +227,7 @@ where rw.Field<string>("Parameter Name") == "Clear Element Before Setting Text"
225227
clearElement = "No";
226228
}
227229

228-
if (clearElement.ToLower() == "yes")
230+
if (clearElement.ToLower() == "yes")
229231
{
230232
element.Clear();
231233
}
@@ -260,7 +262,8 @@ where rw.Field<string>("Parameter Name") == "Clear Element Before Setting Text"
260262
break;
261263

262264
case "Get Text":
263-
case "Get Attribute":
265+
case "Get Attribute":
266+
case "Get Count":
264267

265268
string VariableName = (from rw in v_WebActionParameterTable.AsEnumerable()
266269
where rw.Field<string>("Parameter Name") == "Variable Name"
@@ -274,6 +277,12 @@ where rw.Field<string>("Parameter Name") == "Attribute Name"
274277
if (v_SeleniumElementAction == "Get Text")
275278
{
276279
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();
277286
}
278287
else
279288
{
@@ -443,7 +452,7 @@ public override List<Control> Render(frmCommandEditor editor)
443452
RenderedControls.Add(CommandControls.CreateDefaultLabelFor("v_SeleniumElementAction", this));
444453
RenderedControls.AddRange(CommandControls.CreateUIHelpersFor("v_SeleniumElementAction", this, new Control[] { ElementActionDropdown }, editor));
445454
ElementActionDropdown.SelectionChangeCommitted += seleniumAction_SelectionChangeCommitted;
446-
455+
447456
RenderedControls.Add(ElementActionDropdown);
448457

449458
ElementParameterControls = new List<Control>();
@@ -526,7 +535,8 @@ public void seleniumAction_SelectionChangeCommitted(object sender, EventArgs e)
526535
break;
527536

528537
case "Get Text":
529-
case "Get Matching Elements":
538+
case "Get Matching Elements":
539+
case "Get Count":
530540
foreach (var ctrl in ElementParameterControls)
531541
{
532542
ctrl.Show();

0 commit comments

Comments
 (0)