コード例 #1
0
 /// <summary>Submits a form.</summary>
 public void submit()
 {
     _webElement.Submit();
 }
コード例 #2
0
        private E_ERROR_CODE loginAppsflyerSystem(string userName, string password)
        {
            string message         = string.Empty;
            string elementUserName = _AppsFlyerDataSpiderConfig.getElementUserName();
            string elementPassword = _AppsFlyerDataSpiderConfig.getElementPassword();

            QA.IWebElement searchNameElement               = null;
            QA.IWebElement searchPasswordElement           = null;
            QA.IWebElement submitButtonElement             = null;
            QA.IWebElement searchSubmitDivContainerElement = null;

            if ((elementUserName == null) || (elementPassword == null))
            {
                message = string.Format("Not conmfig element user name <{0}> or password <{1}>.", elementUserName, elementPassword);
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(E_ERROR_CODE.ERROR_NOT_CONFIG_ELEMENT_USER_NAME_OR_PASSWORD);
            }

            searchNameElement = FindElementByName(elementUserName);
            if (searchNameElement == null)
            {
                message = string.Format("Not found element <{0}>.", elementUserName);
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(E_ERROR_CODE.ERROR_NOT_FOUND_ELEMENT_USER_NAME);
            }

            searchPasswordElement = FindElementByName(elementPassword);
            if (searchPasswordElement == null)
            {
                message = string.Format("Not found element <{0}>.", elementPassword);
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(E_ERROR_CODE.ERROR_NOT_FOUND_ELEMENT_PASSWORD);
            }

            SendKeysToElement(searchNameElement, userName);
            SendKeysToElement(searchPasswordElement, password);

            //*[@id="login-form"]/div[6]/button
            searchSubmitDivContainerElement = FindElementByClassName("form-buttons");
            if (searchSubmitDivContainerElement == null)
            {
                message = "Not found element submit button container div.";
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(E_ERROR_CODE.ERROR_NOT_FOUND_FORM_BUTTONS_CONTAINER_ELEMENT);
            }

            submitButtonElement = searchSubmitDivContainerElement.FindElement(QA.By.TagName("button"));
            if (submitButtonElement == null)
            {
                message = "Not found element submit button.";
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(E_ERROR_CODE.ERROR_NOT_FOUND_ELEMENT_SUBMIT_BUTTON);
            }

            try
            {
                _WebDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(20));
                _WebDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(20));
                submitButtonElement.Submit();
            }
            catch (Exception ex)
            {
                message = string.Format("Submit search form faild, error message<{0}>,UA<{1}>.", ex.Message, _UserAgent);
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(E_ERROR_CODE.ERROR_LOGIN_FAILED);
            }

            if (!checkLoginSuccess(userName))
            {
                TakeScreenshot(string.Format("login_failed_{0}.png", CPublic.getDateString(DateTime.Now)));
                message = string.Format("Login failed,task<{0}>,keywords<{1}>.", userName, password);
                _SystemLog.writeLog2Console(LOG_LEVEL.ERR, message);
                return(E_ERROR_CODE.ERROR_LOGIN_FAILED);
            }
            _IsLoginSuccessed = true;
            return(E_ERROR_CODE.OK);
        }