I’m trying to login programatically to https://www.salesgenie.com/Account/LogOn using WebBrwoser control.
The problem is when I click on “Log On”, the browser doesn’t navigate to the next page in the LogonCompleted event.
HtmlElement userName = wBrowser.Document.GetElementById("username");
userName.SetAttribute("value", SomeUserName);
HtmlElement password = wBrowser.Document.GetElementById("password");
password.SetAttribute("value", SomePassword);
wBrowser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(LogonPageLoaded);
wBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(LogonCompleted);
HtmlElement logonForm = wBrowser.Document.GetElementById("logon-submit");
logonForm.InvokeMember("click");
I think this is because the element “logon-submit” calls a JavaScript function or so.
Please, any help would be appreciated.
Check out your 4th line, you’re setting
userNameagain when you should be settingpasswordEDIT
Besides the problem above I’m guessing that you’re trying to invoke the click too soon. The button is created using JavaScript so you have to wait a bit before clicking it. Unfortunately there’s no event that you can listen for to determine when the JavaScript is
donealthough you could test various properties probably. The safest thing is to probably just wait a couple seconds after load before invokingclick.The code below works for me (although I don’t have a valid username and password). I’ve got one button called
button1and one webbrowser calledwebBrowser1. Once the page is visually loaded in the browser clicking the button on the form correctly invokes theclickevent in the browser.