C# 在C代码的用户界面中,有没有一种方法可以等待控件被点击
在编码的ui中,可以使用C# 在C代码的用户界面中,有没有一种方法可以等待控件被点击,c#,coded-ui-tests,C#,Coded Ui Tests,在编码的ui中,可以使用UITestControl.WaitForControlExist(waitTime)等待控件存在。有没有办法等待控件不存在? 我能想到的最好的方法是创建一个如下的扩展方法: public static bool WaitForControlClickable(this UITestControl control, int waitTime = 10000) { Point p; Stopwatch stopwatch = new
UITestControl.WaitForControlExist(waitTime)等待控件存在代码>。有没有办法等待控件不存在?
我能想到的最好的方法是创建一个如下的扩展方法:
public static bool WaitForControlClickable(this UITestControl control, int waitTime = 10000)
{
Point p;
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
while (stopwatch.ElapsedMilliseconds < waitTime)
{
if (control.TryGetClickablePoint(out p))
{
return true;
}
Thread.Sleep(500);
}
return control.TryGetClickablePoint(out p);
}
public static bool WaitForControlClickable(此UITestControl控件,int waitTime=10000)
{
p点;
秒表秒表=新秒表();
秒表。开始();
while(stopwatch.elapsedmillyses
有更好的方法吗?我也在寻找一种相反的方法。因此WaitForControlExists实际上做的是调用公共WaitForControlPropertyEqual,类似于:
return this.WaitForControlPropertyEqual(UITestControl.PropertyNames.Exists, true, timeout);
您的助手可以调用:
public bool WaitForControlPropertyNotEqual(string propertyName,
object propertyValue, int millisecondsTimeout)
此外,正如Kek指出的,还有一个WaitForControlNotExist公共方法
请注意,它们似乎都在使用同一个助手(也是公共的):
publicstaticboolwaitforcondition(T conditionContext,谓词conditionEvaluator,int毫秒估计值)
这个助手实际上是在做一个线程。在当前线程上睡眠,就像你做的一样 如果您只想等待特定的时间长度,您可以在测试中添加:
Playback.Wait(3000);
时间以毫秒为单位。有一系列WaitForControl…()
方法,包括WaitForControlNotExist()
方法
这些Wait…
方法的完整集合是:
WaitForControlEnabled()
WaitForControlExist()
WaitForControlNotExist()
WaitForControlPropertyEqual()
WaitForControlPropertyNotEqual()
WaitForControlReady()
还有WaitForCondition()
和WaitForControlCondition()
可用于等待更复杂条件的方法。很抱歉,我把这个问题给你了,但这个答案对我最初提出的问题同样有用,因为我知道没有可点击的属性,所以我不能等待。我想看看这个程序集,看看所有这些方法是如何实现的(使用反射工具). 它们似乎都指向你所做的事情的同一个方向。你能解释一下为什么回放吗代码>优先于线程睡眠(500)问题中的代码已经使用的代码>根据MSDN,Playback.Wait()允许您在等待结束之前取消播放,而sleep可能不会或引发异常。
WaitForControlEnabled()
WaitForControlExist()
WaitForControlNotExist()
WaitForControlPropertyEqual()
WaitForControlPropertyNotEqual()
WaitForControlReady()