How To Get the HTMLDocument ?

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

How To Get the HTMLDocument ?

Postby Glenn » Thu May 02, 2019 10:36 am

I need to get the HTMLDocument from the browser because I need to set a Form input username and password elements and execute <form> submit button. But I see no way to get the HTML document from the browser. The input elements had NO Id.

-Please Help
Glenn
Newbie
 
Posts: 5
Joined: Thu May 02, 2019 10:27 am

Re: How To Get the HTMLDocument ?

Postby magreenblatt » Thu May 02, 2019 10:50 am

You can iterate through form elements using JavaScript.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: How To Get the HTMLDocument ?

Postby Glenn » Thu May 02, 2019 12:25 pm

How do I do that? I'm not familiar with doing that using CEF.

Thanks, Glenn
Glenn
Newbie
 
Posts: 5
Joined: Thu May 02, 2019 10:27 am

Re: How To Get the HTMLDocument ?

Postby magreenblatt » Thu May 02, 2019 12:28 pm

It is unrelated to CEF. Search the internet for JavaScript usage. You can inject JavaScript into the browser as described here: https://bitbucket.org/chromiumembedded/ ... javascript
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: How To Get the HTMLDocument ?

Postby Glenn » Thu May 02, 2019 8:50 pm

I looked at the page you referenced but don't see a way to set the username and password in the <form> code below and "click" the forms submit button. Can you please help me, I'm desperate?

Code: Select all
<form action="https://www.site.net/index.php?l=login" method="post" style="margin: 0px;">
<table width="100%" border="0">
 <tbody><tr>
        <td width="72%" valign="middle"><input type="text" name="username" size="15" value="Username" onfocus="if(this.value == 'Username') { this.value = ''; } " onblur="if(this.value == '') { this.value = 'Username';}" style="width: 175px; height: 20px; border: 1px solid #ccc; padding: 2px; font-size:13px; color: #666; font-weight: bold; margin-bottom: 10px;float:left;">
        </td>
 </tr>
 <tr>
       <td valign="middle"><input type="password" name="password" size="15" value="Password" onfocus="if(this.value == 'Password') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Password';}" style="width: 175px; height: 20px; border: 1px solid #ccc; padding: 2px; font-size:13px; color: #666; font-weight: bold; margin-bottom: 10px;float:left;">
       </td>
 </tr>
 </tbody></table><input id="submitbutton" type="submit" value="Login"><br>
</form>
Glenn
Newbie
 
Posts: 5
Joined: Thu May 02, 2019 10:27 am

Re: How To Get the HTMLDocument ?

Postby Glenn » Thu May 02, 2019 10:41 pm

I looked at the post at https://github.com/cefsharp/CefSharp/issues/828 and used the code below to set the "username" and "password" and it worked.

Code: Select all
chromeBrowser.ExecuteScriptAsync("$('input[name=username]').val(\"USERNAME\")");
chromeBrowser.ExecuteScriptAsync("$('input[name=password]').val(\"PASSWORD\")");


But can't figure out how to simulate the "Submit" button code below.

<input id="submitbutton" type="submit" value="Login">

I tried this code
Code: Select all
chromeBrowser.ExecuteScriptAsync("$('input[id=submitbutton]').submit();");
but doesn't work. Any ideas?
Glenn
Newbie
 
Posts: 5
Joined: Thu May 02, 2019 10:27 am

Re: How To Get the HTMLDocument ?

Postby amaitland » Fri May 03, 2019 12:53 am

You submit a form, you click a button. If you are new to JavaScript then I suggest you seek help on somewhere like stackoverflow.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: How To Get the HTMLDocument ?

Postby shaukiran » Tue May 21, 2019 7:24 am

I Know it is an old topic, my solution:

public static class HtmlHelpr{

public static HtmlDocument HtmlDocumentFromFile(this string PathToHtml){
using(WebBrowser wb = new WebBrowser()){
string s = File.ReadAllText(PathToHtml);
wb.ScriptErrorsSuppressed = true;
wb.DocumentText = s;
var hd = wb.Document;
hd.Write(s);
return hd;
}
}
}
shaukiran
Newbie
 
Posts: 1
Joined: Tue May 21, 2019 7:19 am


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 19 guests