Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium or Coypu Wait for element show and get time before show

I using Selenium for UI testing.

What I want to when I click on a button once . Then I'll wait until an element exists. And take time on how long it takes . If it takes longer than timeout ms . So it will give 0 or not exist.

I have try this using 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

But it does not quite seem to give right result.

like image 289
eriksv88 Avatar asked Sep 15 '16 13:09

eriksv88


1 Answers

I find one soltuion for 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

And then:

Dim vElementLoadTime As Long = browser.WaitUntilElementIsPresent("#repSearchDocuments > .list-group-item", 20)
like image 89
eriksv88 Avatar answered Oct 14 '22 05:10

eriksv88