Home > Blockchain >  VB - CefSharp not return values
VB - CefSharp not return values

Time:02-21

I can fill a value of a specific field with the code below

nav.EvaluateScriptAsync("document.getElementById('email').value='teste';")

but I can't return the value of this field

Dim placeholder As Task(Of JavascriptResponse) = nav.EvaluateScriptAsync("document.getElementById('email').value")
Task.WaitAll()
MsgBox(placeholder.Result.ToString)

both (placeholder.Result.ToString) and (placeholder.ToString) return "CefSharp.JavascriptResponse"

CodePudding user response:

You can obtain the value from JavascriptResponse.Result property. Check the Success property first, if the script evaluation failed the error will be contained with the Message property.

http://cefsharp.github.io/api/97.1.x/html/Properties_T_CefSharp_JavascriptResponse.htm

CodePudding user response:

I got it that way.

Public Async Function testeAsync() As Task(Of String)

    Dim placeholder2 As JavascriptResponse = Await nav.EvaluateScriptAsync("document.getElementById('email').placeholder")

    If (placeholder2.Success) Then
        MsgBox(placeholder2.Result)
    End If

End Function

But when I do a return in the function and call the function in a struct, how do I call waiting for the async function to complete?

This way the sub prints the result before the asynchronous process ends.

Sub testeResultado()
    Dim returnedTaskTResult As Task(Of String) = testeAsync()
    MsgBox(returnedTaskTResult.ToString)
End Sub
  • Related