private void HandleWindowsGenericWidgetControlAction(ActGenElement actWinC) { IHTMLElement element = mUIAutomationHelper.GetHTMLHelper().GetActElement(actWinC); if (element == null) { actWinC.Error = "Element not Found - " + actWinC.LocateBy + " " + actWinC.LocateValueCalculated; return; } string value = string.Empty; bool result = false; string ValDrv = actWinC.ValueForDriver; try { switch (actWinC.GenElementAction) { case ActGenElement.eGenElementAction.SetValue: result = mUIAutomationHelper.GetHTMLHelper().SetValue(element, ValDrv); if (result) { actWinC.ExInfo = ValDrv + " set"; } else { actWinC.Error = "Unable to set value to " + ValDrv; } break; case ActGenElement.eGenElementAction.SetAttributeValue: string attrName = "value"; string attValue = ValDrv; if (ValDrv.IndexOf("=") > 0) { attrName = ValDrv.Split('=')[0]; attValue = ValDrv.Split('=')[1]; } result = mUIAutomationHelper.GetHTMLHelper().SetValue(element, attValue, attrName); if (result) { actWinC.ExInfo = ValDrv + " set"; } else { actWinC.Error = "Unable to set attribute " + ValDrv; } break; case ActGenElement.eGenElementAction.FireSpecialEvent: value = mUIAutomationHelper.GetHTMLHelper().FireSpecialEvent(element, ValDrv); if (value.StartsWith("Error")) { actWinC.Error = "Unable to fire special event. " + value; } else { actWinC.ExInfo = "Fire special event " + value; } break; case ActGenElement.eGenElementAction.SendKeys: result = mUIAutomationHelper.GetHTMLHelper().SendKeys(element, ValDrv); if (result) { actWinC.ExInfo = ValDrv + " Keys Sent"; } else { actWinC.Error = "Unable to Send Keys " + ValDrv; } break; case ActGenElement.eGenElementAction.GetValue: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "value"); if (string.IsNullOrEmpty(value)) { actWinC.Error = "Unable to Get value of " + ValDrv; } else { actWinC.AddOrUpdateReturnParamActual("Actual", value.ToString()); actWinC.ExInfo = value.ToString(); } break; case ActGenElement.eGenElementAction.ClickAt: result = mUIAutomationHelper.GetHTMLHelper().ClickAt(element, ValDrv); if (result) { actWinC.ExInfo = "Element Clicked"; } else { actWinC.Error = "Element Unable to Clicked"; } break; case ActGenElement.eGenElementAction.Click: case ActGenElement.eGenElementAction.AsyncClick: result = mUIAutomationHelper.GetHTMLHelper().Click(element); if (result) { actWinC.ExInfo = "Element Clicked"; } else { actWinC.Error = "Element Unable to Clicked"; } break; case ActGenElement.eGenElementAction.RightClick: result = mUIAutomationHelper.GetHTMLHelper().RightClick(element, ValDrv); if (result) { actWinC.ExInfo = "Element Right Click Done"; } else { actWinC.Error = "Element Unable to Right Click"; } break; case ActGenElement.eGenElementAction.Enabled: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "disabled"); value = value.ToString().ToLower().Equals("false") ? "true" : "false"; actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); break; case ActGenElement.eGenElementAction.Hover: result = mUIAutomationHelper.GetHTMLHelper().MouseHover(element, ValDrv); if (result) { actWinC.ExInfo = "Element Hover Done"; } else { actWinC.Error = "Unable to Hover the Element"; } break; case ActGenElement.eGenElementAction.ScrollToElement: result = mUIAutomationHelper.GetHTMLHelper().scrolltoElement(element); if (result) { actWinC.ExInfo = "Scroll to Element Done"; } else { actWinC.Error = "Unable to Scroll to Element"; } break; case ActGenElement.eGenElementAction.Visible: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "type"); value = value.Equals("hidden") ? "false" : "true"; actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); break; case ActGenElement.eGenElementAction.SelectFromDropDown: value = mUIAutomationHelper.GetHTMLHelper().SelectFromDropDown(element, ValDrv); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to select value-" + ValDrv + " from DropDown"; } break; case ActGenElement.eGenElementAction.SelectFromDropDownByIndex: result = mUIAutomationHelper.GetHTMLHelper().SetValue(element, ValDrv); if (result) { actWinC.ExInfo = ValDrv + " set"; } else { actWinC.Error = "Unable to Set Value " + ValDrv; } break; case ActGenElement.eGenElementAction.GetInnerText: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, "innerText"); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get Inner Text"; } break; case ActGenElement.eGenElementAction.GetStyle: value = mUIAutomationHelper.GetHTMLHelper().GetStyle(element); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get Element Style"; } break; case ActGenElement.eGenElementAction.GetElementAttributeValue: value = mUIAutomationHelper.GetHTMLHelper().GetValue(element, ValDrv); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get custom attribute"; } break; case ActGenElement.eGenElementAction.GetCustomAttribute: value = mUIAutomationHelper.GetHTMLHelper().GetNodeAttributeValue(element, ValDrv); if (!string.IsNullOrEmpty(value)) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = value.ToString(); } else { actWinC.Error = "Unable to get custom attribute"; } break; case ActGenElement.eGenElementAction.SwitchFrame: value = mUIAutomationHelper.GetHTMLHelper().SwitchFrame(actWinC.LocateBy, actWinC.LocateValueCalculated); if (value.Equals("true")) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = "Switched to frame"; } else { actWinC.Error = "Unable Switch frame"; } break; case ActGenElement.eGenElementAction.HighLightElement: value = mUIAutomationHelper.GetHTMLHelper().HighLightElement(element); if (value.Equals("true")) { actWinC.AddOrUpdateReturnParamActual("Actual", value); actWinC.ExInfo = "Element Highlighted"; } else { actWinC.Error = "Unable To Highlight Element"; } break; default: actWinC.Error = "Unknown Action - " + actWinC.GenElementAction; break; } } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
//Handle all Generic Actions public void GenElementHandler(ActGenElement act) { IWebElement e; switch (act.GenElementAction) { //Click and ClickAt case ActGenElement.eGenElementAction.ClickAt: case ActGenElement.eGenElementAction.Click: e = LocateElement(act); if (e == null) { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValue; return; } else { e.Click(); } break; //Set Value case ActGenElement.eGenElementAction.SetValue: e = LocateElement(act); if (e != null) { if (e.TagName == "select") { SelectElement combobox = new SelectElement(e); string val = act.ValueForDriver; combobox.SelectByText(val); act.ExInfo += "Selected Value - " + val; return; } if (e.TagName == "input" && e.GetAttribute("type") == "checkbox") { ((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].setAttribute('checked',arguments[1])", e, act.ValueForDriver); return; } //Special case for FF if (Driver.GetType() == typeof(FirefoxDriver) && e.TagName == "input" && e.GetAttribute("type") == "text") { e.Clear(); e.SendKeys(GetKeyName(act.ValueForDriver)); } else { ((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].setAttribute('value',arguments[1])", e, act.ValueForDriver); } } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValueCalculated; return; } break; //KeyType - similar to Keyboard Input case ActGenElement.eGenElementAction.KeyType: e = LocateElement(act); if (e != null) { e.Clear(); e.SendKeys(GetKeyName(act.ValueForDriver)); } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValueCalculated; return; } break; //Keyboard Input - similar to KeyType case ActGenElement.eGenElementAction.KeyboardInput: e = LocateElement(act); if (e != null) { e.SendKeys(GetKeyName(act.ValueForDriver)); } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValueCalculated; return; } break; //Check this case ActGenElement.eGenElementAction.GetValue: e = LocateElement(act); if (e != null) { act.AddOrUpdateReturnParamActual("Actual", e.GetAttribute("text")); if (act.GetReturnParam("Actual") == null) { act.AddOrUpdateReturnParamActual("Actual", e.Text); } } else { act.Error = "Error: Element not found - " + act.LocateBy + " " + act.LocateValue; return; } break; //GoToURL - implemented also as GoToURL action and not in GenElementHandler action case ActGenElement.eGenElementAction.GotoURL: string sURL = act.ValueForDriver.ToLower(); if (sURL.StartsWith("www")) { sURL = "http://" + act.ValueForDriver; } else { sURL = act.ValueForDriver; } Driver.Navigate().GoToUrl(sURL); break; //Wait Action case ActGenElement.eGenElementAction.Wait: WaitAction(act); break; //Delete all Cookies case ActGenElement.eGenElementAction.DeleteAllCookies: //TODO: FIXME: This action should not be part of GenElement Driver.Manage().Cookies.DeleteAllCookies(); break; //Back Click case ActGenElement.eGenElementAction.Back: //TODO: FIXME: This action should not be part of GenElement PressBackBtn(); break; case ActGenElement.eGenElementAction.CloseBrowser: Dictionary <String, Object> pars = new Dictionary <String, Object>(); Driver.ExecuteScript("mobile:monitor:stop", pars); break; } }