WebBrowser control automation question
-
Hi I`m trying to automate navigation of a WebBrowser control by automatically filling in some fields and clicking a button to log a user in. I get it working by searching for the appropriate
Input
tags, and then setting their values. I submit the form by callingSendKeys("{Enter}")
. However, I run into trouble sometimes using this SendKeys method, because this means that the WebBrowser control always needs to have focus. The reason why I didn't search for the Login button and calling its click event, is because I don't know how. The username and password fields both have uniquename
andid
fields that identify them. Below is a snippet of Facebook's login page. If anyone can go through this and tell me how I would call the click method on the login button, I would appreciate it. Or can I call a "form submit" method somehow? I've underlined what I think the Login button is:<div class="menu_login_container"><form method="POST" action="https://login.facebook.com/login.php?login_attempt=1" id="login_form" onsubmit=";var d=document.documentElement;if (d.onsubmit) { return d.onsubmit(event); }else { return Event.fire(d, "submit", event); }"><input type="hidden" name="charset_test" value="€,´,€,´,水,Д,Є" /><input type="hidden" id="locale" name="locale" value="en_US" autocomplete="off" /><table cellspacing="0"><tr><td class="html7magic"><label for="email">Email</label></td><td class="html7magic"><label for="pass">Password</label></td></tr><tr><td><input type="text" class="inputtext" name="email" id="email" value="" tabindex="1"></input></td><td><input type="password" class="inputtext" name="pass" id="pass" tabindex="2"**></input></td><td><label class="uiButton uiButtonConfirm uiButtonMedium"><input value="Login" tabindex="4" type="submit"></input></**label></td></tr><tr><td class="login_form_label_field"><input type="checkbox" class="inputcheckbox" value="1" id="persistent" name="persistent" tabindex="3"></input><label id="label_persistent" for="persistent">Keep me logged in</label></td><td class="login_form_label_field"><a href="http://www.facebook.com/reset.php" rel="nofollow">Forgot your password?</a></td></tr></table><input type="hidden" name="cha
-
Hi I`m trying to automate navigation of a WebBrowser control by automatically filling in some fields and clicking a button to log a user in. I get it working by searching for the appropriate
Input
tags, and then setting their values. I submit the form by callingSendKeys("{Enter}")
. However, I run into trouble sometimes using this SendKeys method, because this means that the WebBrowser control always needs to have focus. The reason why I didn't search for the Login button and calling its click event, is because I don't know how. The username and password fields both have uniquename
andid
fields that identify them. Below is a snippet of Facebook's login page. If anyone can go through this and tell me how I would call the click method on the login button, I would appreciate it. Or can I call a "form submit" method somehow? I've underlined what I think the Login button is:<div class="menu_login_container"><form method="POST" action="https://login.facebook.com/login.php?login_attempt=1" id="login_form" onsubmit=";var d=document.documentElement;if (d.onsubmit) { return d.onsubmit(event); }else { return Event.fire(d, "submit", event); }"><input type="hidden" name="charset_test" value="€,´,€,´,水,Д,Є" /><input type="hidden" id="locale" name="locale" value="en_US" autocomplete="off" /><table cellspacing="0"><tr><td class="html7magic"><label for="email">Email</label></td><td class="html7magic"><label for="pass">Password</label></td></tr><tr><td><input type="text" class="inputtext" name="email" id="email" value="" tabindex="1"></input></td><td><input type="password" class="inputtext" name="pass" id="pass" tabindex="2"**></input></td><td><label class="uiButton uiButtonConfirm uiButtonMedium"><input value="Login" tabindex="4" type="submit"></input></**label></td></tr><tr><td class="login_form_label_field"><input type="checkbox" class="inputcheckbox" value="1" id="persistent" name="persistent" tabindex="3"></input><label id="label_persistent" for="persistent">Keep me logged in</label></td><td class="login_form_label_field"><a href="http://www.facebook.com/reset.php" rel="nofollow">Forgot your password?</a></td></tr></table><input type="hidden" name="cha
I just figured it out :) Below is what I used:
if (element.GetAttribute("value") == "Login")
{
element.InvokeMember("click");
}