|
8 | 8 | using System.Xml.Serialization;
|
9 | 9 | using Newtonsoft.Json;
|
10 | 10 | using OpenQA.Selenium;
|
| 11 | +using OpenQA.Selenium.Support.UI; |
11 | 12 | using taskt.UI.CustomControls;
|
12 | 13 | using taskt.UI.Forms;
|
13 | 14 |
|
@@ -68,7 +69,9 @@ public class SeleniumBrowserElementActionCommand : ScriptCommand
|
68 | 69 | [Attributes.PropertyAttributes.PropertyUISelectionOption("Get Matching Elements")]
|
69 | 70 | [Attributes.PropertyAttributes.PropertyUISelectionOption("Wait For Element To Exist")]
|
70 | 71 | [Attributes.PropertyAttributes.PropertyUISelectionOption("Switch to frame")]
|
71 |
| - [Attributes.PropertyAttributes.PropertyUISelectionOption("Get Count")] |
| 72 | + [Attributes.PropertyAttributes.PropertyUISelectionOption("Get Count")] |
| 73 | + [Attributes.PropertyAttributes.PropertyUISelectionOption("Get Options")] |
| 74 | + [Attributes.PropertyAttributes.PropertyUISelectionOption("Select Option")] |
72 | 75 | [Attributes.PropertyAttributes.InputSpecification("Select the appropriate corresponding action to take once the element has been located")]
|
73 | 76 | [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**")]
|
74 | 77 | [Attributes.PropertyAttributes.Remarks("Selecting this field changes the parameters that will be required in the next step")]
|
@@ -261,8 +264,87 @@ where rw.Field<string>("Parameter Name") == "Clear Element Before Setting Text"
|
261 | 264 | }
|
262 | 265 | }
|
263 | 266 |
|
| 267 | + break; |
| 268 | + case "Get Options": |
| 269 | + |
| 270 | + string applyToVarName = (from rw in v_WebActionParameterTable.AsEnumerable() |
| 271 | + where rw.Field<string>("Parameter Name") == "Variable Name" |
| 272 | + select rw.Field<string>("Parameter Value")).FirstOrDefault(); |
| 273 | + |
| 274 | + |
| 275 | + string attribName = (from rw in v_WebActionParameterTable.AsEnumerable() |
| 276 | + where rw.Field<string>("Parameter Name") == "Attribute Name" |
| 277 | + select rw.Field<string>("Parameter Value")).FirstOrDefault().ConvertToUserVariable(sender); |
| 278 | + |
| 279 | + |
| 280 | + var optionsItems = new List<string>(); |
| 281 | + var ele = (IWebElement)element; |
| 282 | + var select = new SelectElement(ele); |
| 283 | + var options = select.Options; |
| 284 | + |
| 285 | + foreach (var option in options) |
| 286 | + { |
| 287 | + var optionValue = option.GetAttribute(attribName); |
| 288 | + optionsItems.Add(optionValue); |
| 289 | + } |
| 290 | + |
| 291 | + var requiredVariable = engine.VariableList.Where(x => x.VariableName == applyToVarName).FirstOrDefault(); |
| 292 | + |
| 293 | + if (requiredVariable == null) |
| 294 | + { |
| 295 | + engine.VariableList.Add(new Script.ScriptVariable() { VariableName = applyToVarName, CurrentPosition = 0 }); |
| 296 | + requiredVariable = engine.VariableList.Where(x => x.VariableName == applyToVarName).FirstOrDefault(); |
| 297 | + } |
| 298 | + |
| 299 | + requiredVariable.VariableValue = optionsItems; |
| 300 | + requiredVariable.CurrentPosition = 0; |
| 301 | + |
| 302 | + |
264 | 303 | break;
|
| 304 | + case "Select Option": |
| 305 | + |
| 306 | + string selectionType = (from rw in v_WebActionParameterTable.AsEnumerable() |
| 307 | + where rw.Field<string>("Parameter Name") == "Selection Type" |
| 308 | + select rw.Field<string>("Parameter Value")).FirstOrDefault(); |
| 309 | + |
| 310 | + string selectionParam = (from rw in v_WebActionParameterTable.AsEnumerable() |
| 311 | + where rw.Field<string>("Parameter Name") == "Selection Parameter" |
| 312 | + select rw.Field<string>("Parameter Value")).FirstOrDefault(); |
| 313 | + |
| 314 | + |
| 315 | + seleniumInstance.SwitchTo().ActiveElement(); |
| 316 | + |
| 317 | + var el = (IWebElement)element; |
| 318 | + var selectionElement = new SelectElement(el); |
| 319 | + |
| 320 | + switch (selectionType) |
| 321 | + { |
| 322 | + case "Select By Index": |
| 323 | + selectionElement.SelectByIndex(int.Parse(selectionParam)); |
| 324 | + break; |
| 325 | + case "Select By Text": |
| 326 | + selectionElement.SelectByText(selectionParam); |
| 327 | + break; |
| 328 | + case "Select By Value": |
| 329 | + selectionElement.SelectByValue(selectionParam); |
| 330 | + break; |
| 331 | + case "Deselect By Index": |
| 332 | + selectionElement.DeselectByIndex(int.Parse(selectionParam)); |
| 333 | + break; |
| 334 | + case "Deselect By Text": |
| 335 | + selectionElement.DeselectByText(selectionParam); |
| 336 | + break; |
| 337 | + case "Deselect By Value": |
| 338 | + selectionElement.DeselectByValue(selectionParam); |
| 339 | + break; |
| 340 | + case "Deselect All": |
| 341 | + selectionElement.DeselectAll(); |
| 342 | + break; |
| 343 | + default: |
| 344 | + throw new NotImplementedException(); |
| 345 | + } |
265 | 346 |
|
| 347 | + break; |
266 | 348 | case "Get Text":
|
267 | 349 | case "Get Attribute":
|
268 | 350 | case "Get Count":
|
@@ -569,7 +651,34 @@ public void seleniumAction_SelectionChangeCommitted(object sender, EventArgs e)
|
569 | 651 | actionParameters.Rows.Add("Variable Name");
|
570 | 652 | }
|
571 | 653 | break;
|
| 654 | + case "Get Options": |
| 655 | + actionParameters.Rows.Add("Attribute Name"); |
| 656 | + actionParameters.Rows.Add("Variable Name"); |
| 657 | + break; |
| 658 | + case "Select Option": |
| 659 | + actionParameters.Rows.Add("Selection Type"); |
| 660 | + actionParameters.Rows.Add("Selection Parameter"); |
| 661 | + |
572 | 662 |
|
| 663 | + DataGridViewComboBoxCell selectionTypeBox = new DataGridViewComboBoxCell(); |
| 664 | + selectionTypeBox.Items.Add("Select By Index"); |
| 665 | + selectionTypeBox.Items.Add("Select By Text"); |
| 666 | + selectionTypeBox.Items.Add("Select By Value"); |
| 667 | + selectionTypeBox.Items.Add("Deselect By Index"); |
| 668 | + selectionTypeBox.Items.Add("Deselect By Text"); |
| 669 | + selectionTypeBox.Items.Add("Deselect By Value"); |
| 670 | + selectionTypeBox.Items.Add("Deselect All"); |
| 671 | + |
| 672 | + //assign cell as a combobox |
| 673 | + if (sender != null) |
| 674 | + { |
| 675 | + ElementsGridViewHelper.Rows[0].Cells[1].Value = "Select By Text"; |
| 676 | + } |
| 677 | + |
| 678 | + ElementsGridViewHelper.Rows[0].Cells[1] = selectionTypeBox; |
| 679 | + |
| 680 | + |
| 681 | + break; |
573 | 682 | case "Wait For Element To Exist":
|
574 | 683 | foreach (var ctrl in ElementParameterControls)
|
575 | 684 | {
|
|
0 commit comments