/// <summary> /// Find element in current element using it's ControlType and Name /// </summary> /// <param name="controlType"></param> /// <param name="elementName"></param> /// <returns></returns> public WinElement FindElementByTypeAndName(ControlType controlType, string elementName) { var strategy = new FindElementStrategy(By.TypeAndName, elementName) { ControlType = controlType }; return(FindElement(strategy)); }
public Element FindElementInElement(string sessionId, string elementId, FindElementStrategy strategy) { var session = GetSession(sessionId); var element = new Element { Id = session.FindElement(new Guid(elementId), strategy) }; return(element); }
internal Guid?FindElementByAutomationId(AutomationElement parentElement, FindElementStrategy strategy) { var element = FindElement(parentElement, new PropertyCondition(AutomationElement.AutomationIdProperty, strategy.Selector)); if (element.Item1 == Guid.Empty) { return(null); } Elements.Add(element.Item1, element.Item2); return(element.Item1); }
private WinElement FindElement(FindElementStrategy strategy) { var elementGuid = WebHelper.FindElement(this, strategy); if (elementGuid == null) { return(null); } var element = new WinElement(Driver, elementGuid); return(element); }
/// <summary> /// Send request to find element in current element /// </summary> /// <param name="root"></param> /// <param name="strategy"></param> /// <returns></returns> internal static Guid?FindElement(WinElement root, FindElementStrategy strategy) { using (var httpClient = new HttpClient()) { var json = JsonConvert.SerializeObject(strategy); var data = new StringContent(json, Encoding.UTF8, "application/json"); var responseMessage = httpClient.PostAsync($"{root.Driver.Uri}/session/{root.Driver.Guid}/element/{root.Guid}/element", data).Result; var result = JsonConvert.DeserializeObject <Element>(responseMessage.Content.ReadAsStringAsync().Result); return(result.Id); } }
internal Guid?FindElement(FindElementStrategy strategy) { switch (strategy.By) { case By.Name: return(FindElementByName(strategy)); case By.AutomationId: return(FindElementByAutomationId(strategy)); case By.TypeAndName: return(FindElementByTypeAndName(strategy)); default: throw new Exception($"Unable to find specified method for strategy: {strategy.By}"); } }
internal Guid?FindElementByTypeAndName(AutomationElement parentElement, FindElementStrategy strategy) { Console.WriteLine("Searching for type and property name"); var automationType = GetType(strategy.ControlType); var condition = new AndCondition( new PropertyCondition(AutomationElement.ControlTypeProperty, automationType), new PropertyCondition(AutomationElement.NameProperty, strategy.Selector)); var element = FindElement(parentElement, condition); if (element.Item1 == Guid.Empty) { return(null); } Elements.Add(element.Item1, element.Item2); return(element.Item1); }
internal Guid?FindElement(Guid parentElementId, FindElementStrategy strategy) { var parentElement = Elements[parentElementId]; switch (strategy.By) { case By.Name: return(FindElementByNameInElement(parentElement, strategy)); case By.AutomationId: return(FindElementByAutomationId(parentElement, strategy)); case By.TypeAndName: return(FindElementByTypeAndName(parentElement, strategy)); default: throw new Exception($"Unable to find specified method for strategy: {strategy.By}"); } }
internal Guid?FindElementByNameInElement(AutomationElement parentElement, FindElementStrategy strategy) { try { Console.WriteLine($"Searching for {strategy.Selector} element in parent element"); var element = FindElement(parentElement, new PropertyCondition(AutomationElement.NameProperty, strategy.Selector)); if (element.Item1 == Guid.Empty) { return(null); } Elements.Add(element.Item1, element.Item2); Console.WriteLine($"Element found"); return(element.Item1); } catch (Exception e) { Console.WriteLine(e.Message); } return(Guid.Empty); }
/// <summary> /// Find element in current element using it's AutomationId /// </summary> /// <param name="automationId"></param> /// <returns></returns> public WinElement FindElementByAutomationId(string automationId) { var strategy = new FindElementStrategy(By.AutomationId, automationId); return(FindElement(strategy)); }
/// <summary> /// Find element in current element using it's name /// </summary> /// <param name="elementName"></param> /// <returns></returns> public WinElement FindElementByName(string elementName) { var strategy = new FindElementStrategy(By.Name, elementName); return(FindElement(strategy)); }
internal Guid?FindElementByTypeAndName(FindElementStrategy strategy) { var session = Elements[SessionId]; return(FindElementByTypeAndName(session, strategy)); }
internal Guid?FindElementByAutomationId(FindElementStrategy strategy) { var session = Elements[SessionId]; return(FindElementByAutomationId(session, strategy)); }