Khalif
Khalif

Reputation: 11

VBA-Selenium run time error, window not found: unable to find element on closed window

however I tried, VBA selenium can't find existing element in a loaded page. Here is the last code I use:

Sub TableData()
Dim driver As New WebDriver
Dim sInfo As String

With driver
    .Start "Internet Explorer"
    .Get "http://cvb.manatron.com/Tabs/PropertySearch.aspx"
    .FindElementById("fldInput").SendKeys ("Carter")
    .FindElementById("btnsearch").Click
    sInfo = .FindElementById("grm-search", timeout:=20000).Text
    Debug.Print sInfo
    .Quit
End With

End Sub

Hope somebody can help. Thanks

Upvotes: 1

Views: 1890

Answers (1)

QHarr
QHarr

Reputation: 84455

This worked for me by adding a delay before the SendKeys and attempting to retrieve sInfo.

Option Explicit

Sub TableData()
Dim driver As New WebDriver
Dim sInfo As String

With driver
    .Start "Chrome" '"Internet Explorer"
    .Get "http://cvb.manatron.com/Tabs/PropertySearch.aspx"
 
     Application.Wait Now + TimeValue("00:00:02")

    .FindElementByCss("#fldInput").SendKeys "Carter"
    .FindElementById("btnsearch").Click
     
    Application.Wait Now + TimeValue("00:00:01")

    sInfo = .FindElementById("grm-search", timeout:=20000).Text
    Debug.Print sInfo
    .Quit
End With

End Sub

Output:

Output of search

Upvotes: 2

Related Questions