我使用Selenium进行UI测试。
当我点击一次按钮时我想要做的事情。然后我会等到一个元素存在。花点时间看看花了多长时间。如果它花费的时间超过超时ms。所以它会给出0或者不存在。
我试过用Coypu:
browser.FindCss("[name=""searchbtn""]").Click()
Dim vStopwatch = Stopwatch.StartNew()
browser.TryUntil(Function() browser.FindXPath("//*[@id=""blockDocumentsSearch""]").Hover(), Function() browser.FindCss("#repSearchDocuments > .list-group-item").Exists(), TimeSpan.FromMilliseconds(500), New Options() With {
.Timeout = TimeSpan.FromMilliseconds(10000)})
If Not browser.FindCss("#repSearchDocuments > .list-group-item").Exists() Then
pTCH.ErrorCurrentStep("Not showing any documents or timeout.", browser)
Return 0
End If
Return vStopwatch.ElapsedMilliseconds但它似乎并没有给出正确的结果。
发布于 2016-09-15 16:05:05
我为Coypu找到了一个独处:
Public Module BrowserSessionExtension
<Extension>
Public Function WaitUntilElementIsPresent(browser As BrowserSession, cssSelector As String, Optional timeout As Integer = 10) As Long
Dim vExist As Boolean = False
Dim vStopwatch = Stopwatch.StartNew()
For i As Integer = 0 To timeout - 1
If browser.FindCss(cssSelector, Options.First).Exists() Then
vExist = True
Exit For
End If
Thread.Sleep(1000)
Next
vStopwatch.Stop()
If vExist Then
Return vStopwatch.ElapsedMilliseconds
Else
Return 0
End If
End Function
End Module然后:
Dim vElementLoadTime As Long = browser.WaitUntilElementIsPresent("#repSearchDocuments > .list-group-item", 20)https://stackoverflow.com/questions/39512690
复制相似问题