|
Rank: Member Groups: Member
Joined: 9/27/2014 Posts: 15
|
Good Morning, I'm trying to auto login to a site with eo.webbrowser. I added a webview1 and a webcontrol1 to the form With normal control webbrowser I use this code:
WebBrowser1.Navigate("http://xxxxxxxx")
While WebBrowser1.IsBusy Or WebBrowser1.ReadyState <> WebBrowserReadyState.Complete Application.DoEvents() End While
WebBrowser1.Document.GetElementById("username").InnerText = "yyyyyyyy" WebBrowser1.Document.GetElementById("password").InnerText = "xxxxxxxx" WebBrowser1.Document.GetElementById("username").Focus()
SendKeys.Send(ControlChars.Cr)
I added a webview1 and a webcontrol1 to the form How can I achieve the same result using eo.webbrowser component?
Some properties such as WebBrowser1.Document.GetElementById ("username"). InnerText or WebBrowser1.IsBusy or WebBrowser1.ReadyState does not exist
I hope you can help me
thanks
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, There are several different ways to do it. One way is to use EvalScript like this:
Code: C#
//Fill the input fields and focus the password field in one call
WebView1.EvalScript(string.Format(@"
document.getElementById('username').innerText = '{0}',
document.getElementById('password').innerText = '{1}',
document.getElementById('username').focus();",
user_name, password);
You can also use something like this:
Code: C#
//Fill the input fields
EO.WebBrowser.DOM.Document doc = WebView1.GetDOMWindow().document;
doc.getElementById("username").innerText = user_name;
doc.getElementById("password").innerText = password;
//Focus the password field
doc.getElementById("password").invokeFunction("focus");
Hope this helps. Thanks!
|
|
Rank: Member Groups: Member
Joined: 9/27/2014 Posts: 15
|
Thanks you for your reply!
I have tried in many ways, but it does not work. The first example I could not prove it, because I have not been able to translate from C # to VB.net passing Format (@ " In any case, the following code works well using a normal control webbrowser:
WebBrowser1.Document.GetElementById("username").InnerText = "my user" WebBrowser1.Document.GetElementById("password").InnerText = "my pw"
Instead with the EO WebView control, I can not enter credentials in the fields of this web page:
WebView1.EvalScript("document.getElementById('username').InnerText = 'my user';") WebView1.EvalScript("document.getElementById('password').InnerText = 'my pw';")
with the address "http://mail.yahoo.com" instead I can run the code, putting ".value" instead of ".InnerText", : WebView1.EvalScript("document.getElementById('username').value = 'my user';") WebView1.EvalScript("document.getElementById('password').value = 'my pw';") But unfortunately it does not work on the login page that interests me. Maybe, I think the problem is in the ".InnerText" that does not work well in Chrome, that is the engine used by the WebView control. In fact, the page to which I try to do the automatic login, don't displays the ID number of the fields username and password, and also ".value" has no effect You can see below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Home</title> <link href="/V/resources/css/stylesheet.css" rel="stylesheet" type="text/css" media="screen"> <link href="/V/resources/css/printer.css" rel="stylesheet" type="text/css" media="print"> <SCRIPT type="text/javascript" src="../js/CalendarPopup.js" > </SCRIPT> </head> <body > <div id="header" class="screen"> <div id="navigation"> </div> <img id="logo" class="screen" src="/V/resources/images/PCS.gif" ></div> <div id="logoprint" class="screenHtml"> ABC <p>DDS</div> <hr/> <div id="contents" class="screen"> <meta http-equiv="Cache-Control" content="max-age=300,must-revalidate"> <DIV class="sfondoMenu" > <hr class="superioreMenu" /> <table class="screen" cellpadding="0" cellspacing="0" border="0" > </table> </DIV></div> <hr/> <div id="main" > <meta http-equiv="Cache-Control" content="max-age=300,must-revalidate"> <table class="normal">
<tr> <TD width="15%"> </TD>
<td><FORM action="/V/login.do" > <fieldset> <LEGEND>login</LEGEND> <table border="0"> <tr> <td width="144" align="right">username:</td> <td><input name="username" type="text" maxlength="20" value="" style="text-transform: none" /></td> </tr> <tr> <td width="144" align="right">password:</td> <td><input name="password" type="password" maxlength="20" value="" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="accedi"></td> </tr> </table> </fieldset> </FORM></td> <TD width="15%"> </TD> </tr>
</table>
</div> </body> </html>
Could you help me find the correct code for automatic access to this page, using the WebView control?
Thanks in advance
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
It doesn't work with your page because you are using getElementById but your username and password input elements do not have an id. As a way to debug, you can try to load the page with Chrome browser, then go to DevTools JavaScript console and enter the script you pass to WebView.EvalScript. If there is a problem with the script, then the JavaScript console will give you an error message. That will help you to find out what's the correct script you should pass to WebView.EvalScript.
Thanks
|
|
Rank: Member Groups: Member
Joined: 9/27/2014 Posts: 15
|
Thanks! I solved this way:
Code: Visual Basic.NET
WebView1.EvalScript("document.getElementsByName('username')[0].value = 'my_username';")
WebView1.EvalScript("document.getElementsByName('password')[0].value = 'my_password';")
However, despite the following command line:
Code: Visual Basic.NET
WebView1.EvalScript("document.getElementsByName('username')[0].focus();")
The control WebView do not accept the click or the "Enter":
Code: Visual Basic.NET
WebView1.EvalScript("document.getElementByInputType('submit')[0].click();")
I have done many tests. For the "Enter" key right after I must necessarily click on the WebView control. Now I have solved by making activate control through SendKeys.Send ("{TAB}"). Now it remains a problem: How can I imitate this following code (WebBroser control) with WebView Control?
Code: Visual Basic.NET
While WebBrowser1.IsBusy Or WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
Thanks you in advance
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, To post back the form, you can call submit method on the form element. For example,
Code: JavaScript
document.getElementById("form1").submit();
You do not need to write a loop to check IsBusy with our control. You do it like this:
Code: Visual Basic.NET
'Load target Url and wait until it finishes
webView1.LoadUrlAndWait(target_url)
This achieves the same result as the following code using MS's WebBrowser:
Code: Visual Basic.NET
'Load the target Url
WebBrowser1.Navigate(target_url)
'Wait until it finishes
While WebBrowser1.IsBusy Or WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
You can find a list of all WebView's properties/methods from the reference section of the documentation: http://www.essentialobjects.com/doc/6/eo.webbrowser.webviewmembers.aspxNote that WebView is not the object that you placed in your form. The object that you placed in your form is a WebControl object. See here for more details about the relationship of WebControl and WebView: http://www.essentialobjects.com/doc/6/start/overview.aspxIn Windows Forms, this is implemented as: 1. When you drag a WebControl (for example, webControl1) into your form, a new WebView (form example, webView1) is also added into your form; 2. The WebControl's WebView property is automatically set to the newly added WebView. You can verify this in the property window for the WebControl; 3. As a result, you can either access the WebView object through the WebControl object, for example, "webControl1.WebView", or to access it directly (for example, webView1); Hope this helps. Thanks
|
|
Rank: Member Groups: Member
Joined: 9/27/2014 Posts: 15
|
Thank you very much for the information, I will study the properties of the control!
|
|
Rank: Member Groups: Member
Joined: 9/27/2014 Posts: 15
|
Hi support, after I have "sign in" the site, how can I wait that the new page is loading complete?
Code: Visual Basic.NET
WebView1.LoadUrlAndWait("http://xxxxxxx")
WebView1.EvalScript("document.getElementsByName('username')[0].value = 'myuser';")
WebView1.EvalScript("document.getElementsByName('password')[0].value = 'mypassw';")
WebView1.EvalScript("document.getElementsByName('username')[0].focus();")
WebView1.SetFocus()
SendKeys.Send("{TAB}")
SendKeys.Send(ControlChars.Cr)
'Now sign-in and load the page
after this code, how can i wait that the webcontrol have finish to load the new page? I have to be sure that the load is finished before proceeding with new instructions. (In my case, the new page load in same webcontrol) I had try with .IsLoading but without result.. Thanks you
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi, The "typical" way to do this is to check IsLoading with a loop like this:
Code: Visual Basic.NET
'Wait until WebView1.IsLoading becomes false
While webView1.IsLoading
webView1.DoEvents()
End While
However this is not reliable because by the time this code is called, the browser engine may not yet started sending out the request yet. In that case IsLoading is already false and the loop will exit immediately. In order to avoid the above situation, you can use something like this:
Code: Visual Basic.NET
Private m_bLoadingStopped As Boolean
Private Sub WebView_IsLoadingChanged(sender As Object, e As EventArgs)
'Set m_bLoadingStopped to true only when IsLoading
'changes from true to false
If Not webView1.IsLoading Then
m_bLoadingStopped = True
End If
End Sub
'Hook up the event handler in your initialization code
AddHandler webView1.IsLoadingChanged, New EventHandler(AddressOf WebView_IsLoadingChanged)
'Reset m_bLoadingStopped before your page posts back
m_bLoadingStopped = False
/Cause the post back
SendKeys.Send(ControlChars.Cr)
'Wait for IsLoading changes from true to false
While Not m_bLoadingStopped
webView.DoEvents()
End While
Hope this helps. Please let us know if this works for you. Thanks!
|
|