本文整理汇总了C#中ISession.AddUIElement方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.AddUIElement方法的具体用法?C# ISession.AddUIElement怎么用?C# ISession.AddUIElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.AddUIElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
{
FindElementRequest request = JsonConvert.DeserializeObject<FindElementRequest>(body);
AutomationElement start = null;
if (urlParams.ContainsKey("id"))
{
start = session.GetUIElement(int.Parse(urlParams["id"]));
}
else
{
start = session.FocusOnCurrentWindow ?
this.uiAutomation.GetFocusedWindowOrRoot() :
AutomationElement.RootElement;
}
IEnumerable elements = null;
if (request.Strategy == "xpath")
{
elements = this.uiAutomation.FindAllByXPath(start, request.Locator);
}
else
{
var property = AutomationElement.AutomationIdProperty;
object locator = request.Locator;
if (request.Strategy == "name")
{
property = AutomationElement.NameProperty;
}
else if (request.Strategy == "class name")
{
property = AutomationElement.ClassNameProperty;
}
else if (request.Strategy == "id")
{
property = AutomationElement.AutomationIdProperty;
}
else if (request.Strategy == "tag name")
{
property = AutomationElement.ControlTypeProperty;
locator = this.uiAutomation.FromTagName(request.Locator);
}
elements = start.FindAll(
TreeScope.Descendants,
new PropertyCondition(property, locator));
}
var list = new List<Dictionary<string, string>>();
foreach (AutomationElement element in elements)
{
int id = session.AddUIElement(element);
list.Add(new Dictionary<string, string> { { "ELEMENT", id.ToString() } });
}
return list;
}
示例2: Handle
public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
{
FindElementRequest request = JsonConvert.DeserializeObject<FindElementRequest>(body);
AutomationElement start = null;
if (urlParams.ContainsKey("id"))
{
start = session.GetUIElement(int.Parse(urlParams["id"]));
}
else
{
start = session.FocusOnCurrentWindow ?
this.uiAutomation.GetFocusedWindowOrRoot() :
AutomationElement.RootElement;
}
AutomationElement element = null;
if (request.Strategy == "xpath")
{
element = this.uiAutomation.FindFirstByXPath(start, request.Locator);
}
else
{
// TODO throw exceptions to indicate other strategies are not supported.
var property = AutomationElement.AutomationIdProperty;
object locator = request.Locator;
if (request.Strategy == "name")
{
property = AutomationElement.NameProperty;
}
else if (request.Strategy == "class name")
{
property = AutomationElement.ClassNameProperty;
}
else if (request.Strategy == "id")
{
property = AutomationElement.AutomationIdProperty;
}
else if (request.Strategy == "tag name")
{
property = AutomationElement.ControlTypeProperty;
locator = this.uiAutomation.FromTagName(request.Locator);
}
element = start.FindFirst(
TreeScope.Descendants,
new PropertyCondition(property, locator));
}
if (element == null)
{
throw new NoSuchElementException(request.Strategy, request.Locator);
}
int id = session.AddUIElement(element);
return new Dictionary<string, string> { { "ELEMENT", id.ToString() } };
}
示例3: Handle
public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
{
var element = this.uiAutomation.FocusedElement;
this.overlay.Clear();
this.overlay.HighlightedElement = element;
this.overlay.ShowAndWait(session.Capabilities.OverlayHighlightDelay);
int id = session.AddUIElement(element.AutomationElement);
return new Dictionary<string, string> { { "ELEMENT", id.ToString() } };
}
示例4: Handle
public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
{
var request = JsonConvert.DeserializeObject<FindElementsRequest>(body);
IElement context = null;
if (urlParams.ContainsKey("id"))
{
context = this.elementFactory.GetElement(
session.GetUIElement(int.Parse(urlParams["id"])));
}
else
{
context = this.elementFactory.GetElement(
session.FocusOnCurrentWindow ?
this.uiAutomation.GetFocusedWindowOrRoot() :
AutomationElement.RootElement);
}
IList<IElement> elements = null;
var stopwatch = new Stopwatch();
stopwatch.Start();
do
{
elements = this.searcher.FindAll(context, request.Strategy, request.Locator);
}
while (elements.Count == 0 && stopwatch.ElapsedMilliseconds < session.ImplicitWaitMillis);
this.overlay.Clear();
this.overlay.ContextElement = context;
this.overlay.HighlightedElements = elements;
this.overlay.ShowAndWait(session.Capabilities.OverlayHighlightDelay);
var list = new List<Dictionary<string, string>>();
foreach (IElement element in elements)
{
int id = session.AddUIElement(element.AutomationElement);
list.Add(new Dictionary<string, string> { { "ELEMENT", id.ToString() } });
}
return list;
}
示例5: Handle
public object Handle(Dictionary<string, string> urlParams, string body, ref ISession session)
{
FindElementRequest request = JsonConvert.DeserializeObject<FindElementRequest>(body);
IElement context = null;
if (urlParams.ContainsKey("id"))
{
context = this.elementFactory.GetElement(
session.GetUIElement(int.Parse(urlParams["id"])));
}
else
{
context = this.elementFactory.GetElement(
session.FocusOnCurrentWindow ?
this.uiAutomation.GetFocusedWindowOrRoot() :
AutomationElement.RootElement);
}
IElement element = null;
var stopwatch = new Stopwatch();
stopwatch.Start();
do
{
element = this.searcher.FindFirst(context, request.Strategy, request.Locator);
}
while (element == null && stopwatch.ElapsedMilliseconds < session.ImplicitWaitMillis);
this.overlay.Clear();
this.overlay.ContextElement = context;
this.overlay.HighlightedElement = element;
this.overlay.ShowAndWait(session.Capabilities.OverlayHighlightDelay);
if (element == null)
{
throw new NoSuchElementException(request.Strategy.ToString(), request.Locator);
}
int id = session.AddUIElement(element.AutomationElement);
return new Dictionary<string, string> { { "ELEMENT", id.ToString() } };
}