什么是等待页面上的元素的更好方法Waitforcomplete()或system.threading.thread.sleep()

sam*_*sam 1 cruisecontrol.net nunit watin

我在watiN中使用WaitforComplete()但它似乎不能正常工作.即使您有更长的等待时间,它也会执行下一个语句.我正在使用thread.sleep()来停止我的应用程序,直到它获得所需的页面或元素.但事情是页面非常动态,有时需要更长的时间.

更好的解决方案.任何能够捕获页面的东西都会动态返回,并且不会在应用程序中执行下一个语句.

代码示例

    'Show Details page
    Assert.AreEqual("Confirmation", _internetExplorer.Title)

    If (_internetExplorer.Button(Find.ById(New Regex("btnFinish"))).Exists) Then
        _internetExplorer.Button(Find.ById(New Regex("btnFinish"))).Click()
    Else
        Assert.Fail("Could not Find Finish Booking Button on Confirmation Page")
    End If

    System.Threading.Thread.Sleep(100000)
Run Code Online (Sandbox Code Playgroud)

'显示预订摘要页面Assert.AreEqual("显示预订",_internetExplorer.Title)

我想要一些动态检测页面返回的东西.而不是提供一些恒定的价值.

Jer*_*nen 5

只有在某些操作后有回发时,WaitForComplete才能正常工作.否则你必须找到别的东西等待.下面是一个关于如何等待指定标题的示例:

_internetExplorer.Element("title", "Confirmation").WaitUntilExists();
Run Code Online (Sandbox Code Playgroud)

我总是更喜欢使用WaitXXX方法而不是Thread.Sleep,因为WaitXXX方法只会等到达到约束.睡眠等待你指定的时间.如果它很长,时间就会缩短.如果它简短,就会出现问题.

HTH,Jeroen