Search code examples
wpffindcefsharp

Get full text based on partial text in cefsharp wpf


In my xml I have a cefsharp browser:

<cefsharpwpf:ChromiumWebBrowser LoadingStateChanged="browser_LoadingStateChanged" IsBrowserInitializedChanged="browser_IsBrowserInitializedChanged"  x:Name="browser" Margin="0,0,0,-384.2"></cefsharpwpf:ChromiumWebBrowser>

In my c# I have a LoadingStateChanged which determines what site cefsharp is on. I tell cefsharp to go to the google login page where the user can then type in their google login information to be logged into google. When they are logged in, I want to be able to get their username from the google home page:

google home page view

The part which says Welcome, {User Name}, I would like to get the text which is {User Name} but it doesn't have a specific value so I would have to look it up from the Welcome part. I have tried to search it up but I have found no answers. There is a .Find() but it doesn't work that way. Any help would be appreciated!


Solution

  • It looks like cefsharp browser has a method to get the page's HTML:

    https://cefsharp.github.io/api/51.0.0/html/M_CefSharp_WebBrowserExtensions_GetSourceAsync.htm

    You could try getting the HTML of the page after it loads, search for the Welcome string within it, and extract the part containing the name.