【发布时间】:2020-05-02 05:13:51
【问题描述】:
我正在使用带有 C# 的 WinAppDriver 实现 UWP 应用程序的自动化,但在某些时候我的测试失败了,因为某些元素需要时间才能出现,并且我无法应用 waitDriverWait(猜 WAD 没有这个)所以我发现下面的代码正在工作,但想知道是否有更好的方法?
public static void WaitForElement(this WindowsDriver<WindowsElement> driver, string IDType, string elementName, int time = 10000)
{
var wait = new DefaultWait<WindowsDriver<WindowsElement>>(BasePage.WindowsDriver)
{
Timeout = TimeSpan.FromSeconds(time),
PollingInterval = TimeSpan.FromSeconds(0.5)
};
wait.IgnoreExceptionTypes(typeof(InvalidOperationException));
wait.Until(driver1 =>
{
int elementCount = 0;
switch (IDType)
{
case "id":
elementCount = driver1.FindElementsByAccessibilityId(elementName).Count;
break;
case "xpath":
elementCount = driver1.FindElementsByXPath(elementName).Count;
break;
case "name":
elementCount = driver1.FindElementsByName(elementName).Count;
break;
}
return elementCount > 0;
});
}
【问题讨论】:
标签: c# uwp automation appium winappdriver