Page 1 of 1

Getting text from webpage

PostPosted: Sat Jan 15, 2022 8:38 am
by catflap999
Hi

I just started using cefsharp and it's looking good so far, but I'm a bit stuck now, so need some help.

I've created a form in vb.net with a chromium web browser on it. I've got the code sorted to navigate to a website OK, wait for the page to finish loading, and then press a button.

What I now need to do is copy the text on tha page to a string variable so I can do some searching for certain keywords.

How do I get access to the text currently displayed on the web browser please?

Thanks for reading!

Re: Getting text from webpage

PostPosted: Sat Jan 15, 2022 2:40 pm
by amaitland

Re: Getting text from webpage

PostPosted: Mon Jan 17, 2022 4:01 am
by catflap999
Thanks for reply. I tried:

Dim mytext = browser1.GetTextAsync

but this just gives me:

Code: Select all
Id = 4, Status = WaitingForActivation {1}, Method = "{null}", Result = "{Not yet computed}"
AsyncState: Nothing
CancellationPending: False
CreationOptions: None {0}
Exception: Nothing
Id: 4
Result: Nothing
Status: WaitingForActivation {1}


So presumably I need to 'activate' the control first? - how do I do that?

EDIT: by the way, I am waiting for browser.IsLoading = False before trying to get the text, if that's relevant?

Re: Getting text from webpage

PostPosted: Mon Jan 17, 2022 4:27 am
by amaitland
The method returns a Task, you should await the task to get the result.

https://docs.microsoft.com/en-us/dotnet ... pts/async/

Nothing to do with activating the control.

Re: Getting text from webpage

PostPosted: Mon Jan 17, 2022 5:41 am
by catflap999
Hi

I'm afraid I'm not familiar with this? - any chance you could provide some sample code please?

Re: Getting text from webpage

PostPosted: Mon Jan 17, 2022 2:38 pm
by amaitland
It's a standard language feature, plenty of resources online covering the topic. Vb.net is not something I can help you with.

Quick search brings up https://stackoverflow.com/a/41065216/4583726

Past that you'll have to do your own research.

Re: Getting text from webpage

PostPosted: Tue Jan 18, 2022 3:47 am
by catflap999
Thanks for the pointer - I'll look into it.