I am working on a small project based on CEFSharp in C#.
I want to know the procedure to access DOM Elements using CEFSharp in C#. I have all initial things setup already, just need to access the elements. I know how to do this with the built-in web Browser of C# but I cannot find any proper information about doing this with CEFSharp.
I am using the following line of code to access the DOM element of the webpage in a button click listener (separate class than browser class).
private void button1_Click(object sender, EventArgs e)
{brow.chromeBrowser.ExecuteScriptAsync("document.getElementsByName('q').value='Hello';");
}
where brow=CEF browser class object, chromeBrowser=browser instance
With the above code modified like ("alert('My Message')"), I can get an alert message easily with the JavaScript, no problem with that, but I want to access a specific element of DOM, and here nothing works.
Well I found the answer by myself, just a slight change. Hope it helps someone else too
brow.chromeBrowser.ExecuteScriptAsync("document.getElementsByName('q')[0].value='Hello';");
It was a small typo in javascript line . I wrote [0] in the above syntax and everything worked fine. The textfield on the webpage got filled with my text (Hello) after my button click.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With