How to get all Class names from CefSharp Browser URL

Andreas ss 726 Reputation points
2021-07-11T23:58:38.523+00:00

Hello,

I am using the CefSharp Chromium browser control.

I now enter the url: "https://www.test.com/". Now I try to get all class names which exist on this URL using the code below but I get the error for this line like this:

MessageBox.Show($"{((dynamic)result.Result).Count}"); //**Cannot perform runtime binding on a null reference**  

I wonder how I can get all class names which exist on this URL, - in a List correctly with the below code?

This code installs the cefsharp browser from Nuget:
Install-Package CefSharp.WinForms -Version 91.1.211

Thank you!

using CefSharp;  
using CefSharp.WinForms;  
  
        public ChromiumWebBrowser browser;  
        public void InitBrowser()  
        {  
            Cef.Initialize(new CefSettings());  
            browser = new ChromiumWebBrowser("https://uniswapv3.flipsidecrypto.com");  
            this.Controls.Add(browser);  
            browser.Dock = DockStyle.Fill;  
        }  
        public Form1()  
        {  
            InitializeComponent();  
            InitBrowser();      
        }  
  
        async void getAllClasses()  
        {  
            var script = @"(function() { return document.querySelectorAll('[class]'); })();";  
            var result = await browser.EvaluateScriptAsync(script);  
  
            //How to get all classes in a List?  
            List<String> allClassLIST = new List<String>();  
            MessageBox.Show($"{((dynamic)result.Result).Count}"); //Cannot perform runtime binding on a null reference  
        }  




  
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,232 questions
0 comments No comments
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,571 Reputation points
    2021-07-12T02:22:21.593+00:00

    Please note that the await browser.EvaluateScriptAsync method does not get any substantive content, result.Result is null.

    113639-1.png

    We cannot cast null to dynamic.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful