hello i am doing an automation program. the start of the program is to login
and here is the html tag
<form name="LoginForm" method="post" action="https://admin">
<input type="hidden" name="redirectURL" value="Admin/">
<input type="hidden" name="reason" value="LOGIN_REQUIRED">
<fieldset style="padding: 5px 5px 5px 5px;">
<table style="width: 100%">
<tr>
<th style="text-align: left">
<label for="login">
E-mail Address
</label>
</th>
<td style="width: 65%">
<input type="text" name="login" maxlength="80" value="" id="login" style="width:98%">
</td>
</tr>
<tr>
<td></td>
<td>
<div class="field_error" style="clear: left;">
</div>
</td>
</tr>
<tr>
<th style="text-align: left">
<label for="password">
Password
</label>
</th>
<td>
<input type="password" name="password" maxlength="64" value="" style="width:98%">
</td>
</tr>
<tr>
<td></td>
<td>
<div class="field_error" style="clear: left;">
</div>
</td>
</tr>
</table>
<hr style="visibility: hidden;"/>
<div style="width: 60px; margin-left: auto; margin-right: auto">
<input type="submit" name="action" value="Log In" style="text-align:center;" class="generic_button">
</div>
</fieldset>
</form>
but why i can't set the value of the password textbox.
im using wpf and awesomium
i can set the textbox value of the username but i can't set the value of the password
here is my code
wb.ExecuteJavascript(String.Format("document.querySelector('#login').value = '{0}'", txtUsername.Text));
wb.ExecuteJavascript(String.Format("document.querySelector('#password').value = '{0}'", txtPassword.Text));
how can i set the value of password? it doesn't use ID? thank you. it use name attribute
i tried using the built in webbrowser and i can make it work
here is the code:
System.Windows.Forms.HtmlElementCollection elems = wb.Document.GetElementsByTagName("input");
foreach (System.Windows.Forms.HtmlElement elem in elems)
{
String nameStr = elem.GetAttribute("name");
if (nameStr != null && nameStr.Length != 0)
{
if (nameStr == "login")
{
elem.SetAttribute("value", txtUsername.Text);
}
if (nameStr == "password")
{
elem.SetAttribute("value", txtPassword.Text);
}
}
}
Edit: Solution: i changed the awesomium to geckofx. and convert the code above with the code of geckofx
Try this
wb.ExecuteJavascript(String.Format("document.querySelector('input[name=\"password\"]').value = '{0}'", txtPassword.Text));
JSFiddle can be found here: