public string Execute(WebBrowser browser, HtmlElement btn) { bool loadFinished = false; int counterTimeOut = 500; string message; try { browser.DocumentCompleted += delegate { loadFinished = true; }; HTMLInputElementClass iElement = (HTMLInputElementClass)btn.DomElement; iElement.click(); while (!loadFinished && counterTimeOut > 0) { Thread.Sleep(100); Application.DoEvents(); counterTimeOut--; } message = string.Format("Button {0} clicked", btn.InnerHtml.ToString()); } catch (Exception ex) { message = ex.ToString(); } return(message); }
public static void ClickButton(string buttonId) { HTMLInputElementClass input = (HTMLInputElementClass)GetElementById(buttonId); input.click(); WaitForComplete(); }
public void ClickButton(string buttonId) { isDocumentComplete = false; HTMLInputElementClass input = GetInputElement(buttonId); input.click(); WaitForComplete(); }
public void RefreshTestNew() { IEOperateCore ieCore = new IEOperateCore("www.baidu.com"); //ieCore.Refresh(); HTMLInputElementClass searchTextBox = ieCore.GetInputElementByID <HTMLInputElementClass>("kw"); searchTextBox.value = "China"; HTMLInputElementClass searchButton = ieCore.GetInputElementByID <HTMLInputElementClass>("su"); searchButton.click(); }
private void WebBrowserLogin() { Debug.WriteLine("Login URL\r\n\r\n{0}\r\n", (object)_loginBrowserHtmlDocument.location.href); // Wait for login.live.com page Debug.WriteLine("Waiting for host to switch to login.live.com"); bool success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => { try { return (_loginBrowserHtmlDocument.location.host.EndsWith("login.live.com") && _loginBrowserHtmlDocument.location.pathname.StartsWith("/oauth20_authorize.srf")); } catch (Exception) { return(false); } }); if (!success) { throw new LoginException("Failed waiting for login.live.com login page"); } // Wait for login page to load Debug.WriteLine("Wait until login.live.com login page is loaded"); success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => _loginBrowserHtmlDocument.readyState == "complete"); if (!success) { throw new LoginException("Unable to load the login.live.com login page"); } IHTMLElementCollection passwdElementCollection = null; success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => { passwdElementCollection = _loginBrowserHtmlDocument.getElementsByName("passwd"); return(passwdElementCollection.length == 1); }); if (!success) { throw new LoginException("Unable to get password field element"); } // Get the login page elements Debug.WriteLine("Get the login page elements"); HTMLInputElementClass passwordInputElement = null; HTMLInputElementClass signInButtonElement = null; success = TimedOutOperation(kLoginPageReadyTimeout, kOperationRetryDelay, () => { passwordInputElement = (HTMLInputElementClass)((IHTMLElementCollection3)passwdElementCollection).namedItem("passwd"); signInButtonElement = (HTMLInputElementClass)_loginBrowserHtmlDocument.getElementById("idSIButton9"); return(passwdElementCollection != null && signInButtonElement != null); }); if (!success) { throw new LoginException("Unable to get login form elements"); } // Update password LoginBrowserSetInputFieldValue(passwordInputElement, _password); // Click Sign In button Debug.WriteLine("Click Sign In button"); signInButtonElement.click(); }