Example #1
0
        public void BeginRegister(string firstname, string lastname, string login, string pass, string mailToConfirmation, string answerToQuestion, bool deathByCaptcha = true)
        {
            //driver.Navigate().GoToUrl("http://deathbycaptcha.com");
            driver.Navigate().GoToUrl("https://login.inbox.lv/signup");
            WebDriverWait waiter           = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement   loginElement     = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("signup_user")));
            IWebElement   firstnameElement = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("signup_forename")));
            IWebElement   lastnameElement  = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("signup_surname")));
            IWebElement   pass1Element     = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("signup_password_password")));
            IWebElement   pass2Element     = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("signup_password_passwordRepeat")));
            IWebElement   nextBtn          = waiter.Until(ExpectedConditions.ElementToBeClickable(By.Id("btn-privacy-scroll")));

            try
            {
                while (true)
                {
                    nextBtn.Click();
                }
            }
            catch (Exception)
            {
            }

            IWebElement termsButton1 = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("(//label[@class='control-label'])[1]")));
            IWebElement termsButton2 = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("(//label[@class='control-label'])[2]")));
            IWebElement finishButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.Id("signup_submit")));

            loginElement.SendKeys(login);
            firstnameElement.SendKeys(firstname);
            lastnameElement.SendKeys(lastname);
            pass1Element.SendKeys(pass);
            pass2Element.SendKeys(pass);
            termsButton1.Click();
            termsButton2.Click();
            finishButton.Click();


            while (true)
            {
                IWebElement    imageCaptcha = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//img[@class='captcha__img img-responsive']")));
                IWebElement    imageInput   = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("signup_userpin")));
                IWebElement    submitButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[@class='btn btn-primary']")));
                ICaptchaSolver solver;
                if (deathByCaptcha)
                {
                    solver = new DeathByCaptchaSolver();
                }
                else
                {
                    solver = new UserCaptchaSolver();
                }
                var textCaptcha = solver.SolveBytes(driver.GetScreenshot(imageCaptcha));
                if (string.IsNullOrEmpty(textCaptcha))
                {
                    IWebElement changeImageElement = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[contains(@id, 'aptcha__regenerate_captcha')]")));
                    changeImageElement.Click();
                    Task.Delay(5000).Wait();
                    continue;
                }
                imageInput.SendKeys(textCaptcha);
                submitButton.Click();
                //////// pojawia sie jebana recaptcha
                Func <IWebDriver, bool> untilAfterClick = (d) =>
                {
                    try
                    {
                        IWebElement nextPageText = driver.FindElement(By.XPath("//*[contains(@class,'alert alert-success alert-dismissible')]"));
                        if (nextPageText.Displayed && nextPageText.Text.Contains("Registration completed successfully"))
                        {
                            return(true);
                        }
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        var errorCaptcha = driver.FindElement(By.XPath("//*[contains(@class, 'alert alert-danger alert-dismissible')]"));
                        if (errorCaptcha.Text.Contains("Security code entered incorrectly"))
                        {
                            throw new RegisterException(RegisterException.RegisterError.CaptchaError);
                        }
                        else if (errorCaptcha.Text.Contains("Please validate your are not a robot!"))
                        {
                            throw new RegisterException(RegisterException.RegisterError.AdditionalRecaptcha);
                        }
                        else
                        {
                            throw new RegisterException(RegisterException.RegisterError.AnotherError);
                        }
                    }
                    catch (RegisterException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                };
                try
                {
                    waiter.Until(untilAfterClick);
                }
                catch (RegisterException e) when(e.error == RegisterException.RegisterError.AdditionalRecaptcha)
                {
                    if (deathByCaptcha)
                    {
                        solver = new DeathByCaptchaSolver();
                    }
                    else
                    {
                        solver = new UserCaptchaSolver();
                    }
                    //solver.SolveRecaptcha();
                }
                catch (RegisterException e) when(e.error == RegisterException.RegisterError.CaptchaError)
                {
                    solver.Report(); /// przetestowac
                    continue;
                }
                submitButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.Id("btn_proceed")));
                submitButton.Click();

                submitButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[text()='Close']")));
                submitButton.Click();

                SelectElement selectQuestion = new SelectElement(waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("pass_recovery_question_form_question"))));
                int           idToSelect     = new Random().Next(1, selectQuestion.Options.Count - 2);
                selectQuestion.SelectByIndex(idToSelect);
                IWebElement answerInput = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("pass_recovery_question_form_answer")));
                answerInput.SendKeys(answerToQuestion);

                submitButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@class='btn btn-primary']")));
                submitButton.Click();

                submitButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[text()='Close']")));
                submitButton.Click();

                SelectElement birthDay       = new SelectElement(waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("bday"))));
                SelectElement birthMount     = new SelectElement(waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//select[@name='_bmon']"))));
                IWebElement   birthYearInput = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@name='_byear']")));
                SelectElement gender         = new SelectElement(waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("gender"))));

                birthYearInput.SendKeys(string.Format("{0:0000}", new Random().Next(1970, 2001)));
                birthDay.SelectByIndex(new Random().Next(1, 25));
                birthMount.SelectByIndex(new Random().Next(1, 12));
                gender.SelectByIndex(2);

                submitButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.Id("btn_save")));
                submitButton.Click();

                untilAfterClick = (d) =>
                {
                    try
                    {
                        IWebElement nextPageText = driver.FindElement(By.XPath("div[contains(@class, 'alert alert-success')]"));
                        if (nextPageText.Displayed && nextPageText.Text.Contains("Your preferences have been updated"))
                        {
                            return(true);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    return(false);
                    /// dojebac tu cos jeszce
                    //try
                    //{
                    //    var errorCaptcha = driver.FindElement(By.XPath("//*[contains(@class, 'alert alert-danger alert-dismissible')]"));
                    //    if (errorCaptcha.Text.Contains("Security code entered incorrectly"))
                    //        throw new RegisterException(RegisterException.RegisterError.CaptchaError);
                    //    else if (errorCaptcha.Text.Contains("Please validate your are not a robot!"))
                    //        throw new RegisterException(RegisterException.RegisterError.AdditionalRecaptcha);
                    //    else
                    //        throw new RegisterException(RegisterException.RegisterError.AnotherError);
                    //}
                    //catch (RegisterException)
                    //{
                    //    throw;
                    //}
                    //catch (Exception)
                    //{
                    //    return false;
                    //}
                };
                waiter.Until(untilAfterClick);

                break;
            }
        }
Example #2
0
        public void Login(string login, string pass, bool decaptcher = true)
        {
            WebDriverWait waiter = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

            driver.Navigate().GoToUrl("https://www.neobux.com/m/l/");

            IWebElement loginElement = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("Kf1")));
            IWebElement passElement  = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("Kf2")));
            IWebElement submitButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.Id("botao_login")));
            IWebElement captchaInput = driver.IsPresentAndVisible(By.Id("Kf3"));
            IWebElement captchaImage = driver.IsPresentAndVisible(By.XPath("//table/tbody/tr/td[2]/img"));

            Func <IWebDriver, bool> watingForLoad = (driver) =>
            {
                try
                {
                    IWebElement nextPageText = driver.FindElement(By.XPath("//*[@id='navAds']/a/span[text()='View Advertisements']"));
                    return(nextPageText.Displayed);
                }
                catch (Exception)
                {
                }

                try
                {
                    var errorCaptcha = driver.FindElement(By.XPath("//*[@class='f_r' and contains(@style, 'bd0000')]"));
                    throw new LoginException(errorCaptcha.Text);
                }
                catch (LoginException)
                {
                    throw;
                }
                catch (Exception)
                {
                    return(false);
                }
            };

            if (captchaInput != null)
            {
                while (true)
                {
                    loginElement = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("Kf1")));
                    passElement  = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("Kf2")));
                    submitButton = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("botao_login")));
                    loginElement.SendKeys(login);
                    passElement.SendKeys(pass);

                    captchaInput = driver.IsPresent(By.Id("Kf3"));
                    captchaImage = driver.IsPresent(By.XPath("//table/tbody/tr/td[2]/img"));

                    ICaptchaSolver solver;
                    if (decaptcher)
                    {
                        solver = new DeathByCaptchaSolver();
                    }
                    else
                    {
                        solver = new UserCaptchaSolver();
                    }

                    string base64captcha = captchaImage.GetAttribute("src");
                    string captchaText   = solver.SolveBase64(base64captcha);
                    if (string.IsNullOrWhiteSpace(captchaText))
                    {
                        driver.Navigate().Refresh();
                        continue;
                    }
                    if (captchaText.Count(a => char.IsLetter(a)) != 5 || captchaText.Length != 5)
                    {
                        solver.Report();
                        driver.Navigate().Refresh();
                        continue;
                    }
                    captchaInput.SendKeys(captchaText);
                    submitButton.Click();

                    try
                    {
                        waiter.Until(watingForLoad);
                    }
                    catch (LoginException e) when(e.error == LoginException.LoginErrors.CaptchaError)
                    {
                        solver.Report();
                        driver.Navigate().Refresh();
                        continue;
                    }

                    break;
                }
            }
            else
            {
                loginElement.SendKeys(login);
                passElement.SendKeys(pass);
                submitButton.Click();
                waiter.Until(watingForLoad);
            }
        }
Example #3
0
        public void BeginRegister(string email, string login, string pass, bool decaptcher = true)
        {
            driver.Navigate().GoToUrl("https://www.neobux.com/m/r/");
            WebDriverWait waiter        = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement   loginInput    = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("nomedeutilizador")));
            IWebElement   pass1Input    = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("palavrapasse")));
            IWebElement   pass2Input    = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("palavrapasseconfirmacao")));
            IWebElement   emailInput    = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("emailprincipal")));
            IWebElement   birthdayInput = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("anonascimento")));



            loginInput.SendKeys(login);
            pass1Input.SendKeys(pass);
            pass2Input.SendKeys(pass);
            emailInput.SendKeys(email);
            birthdayInput.SendKeys("1990");
            while (true)
            {
                IWebElement captchaInput   = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("codigo")));
                IWebElement captchaImage   = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//table/tbody/tr/td[2]/img")));
                IWebElement agree1Checkbox = waiter.Until(ExpectedConditions.ElementIsVisible(By.Name("tosagree")));
                IWebElement agree2Checkbox = waiter.Until(ExpectedConditions.ElementIsVisible(By.Name("ppagree")));
                IWebElement sendButton     = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("botao_registo")));

                agree1Checkbox.Click();
                agree2Checkbox.Click();

                Captcha captcha = null;

                ICaptchaSolver solver;
                if (decaptcher)
                {
                    solver = new DeathByCaptchaSolver();
                }
                else
                {
                    solver = new UserCaptchaSolver();
                }

                string base64captcha = captchaImage.GetAttribute("src");
                string captchaText   = solver.SolveBase64(base64captcha);

                if (string.IsNullOrWhiteSpace(captchaText))
                {
                    driver.Navigate().Refresh();
                    continue;
                }
                captchaInput.SendKeys(captchaText);

                sendButton.Click();

                try
                {
                    waiter.Until(driver =>
                    {
                        try
                        {
                            IWebElement nextPageButton = driver.FindElement(By.XPath("//*[@id='botao_registo']/span[contains(text(),'finish registration')]"));
                            return(nextPageButton.Displayed && nextPageButton.Enabled);
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            var errorMessagess = driver.FindElements(By.XPath("//*[@id='form_registo']/div[2]/ul/li")).Select(a => a.Text);
                            if (errorMessagess.Count() == 0)
                            {
                                throw new Exception();
                            }

                            throw new RegistrationException(errorMessagess.ToArray());
                        }
                        catch (RegistrationException)
                        {
                            throw;
                        }
                        catch (Exception)
                        {
                            return(false);
                        }
                    }); /// oblusga blednego captcha
                }
                catch (RegistrationException e) when(e.errors.Length == 1 && e.errors[0] == RegistrationException.RegistrationErrors.CaptchaError)
                {
                    solver.Report();
                    driver.Navigate().Refresh();
                    continue;
                }

                break;
            }
        }
Example #4
0
        public void FinishRegister(string code, bool decaptcher = true)
        {
            WebDriverWait waiter = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

            while (true)
            {
                IWebElement codeInput    = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='form_registo']/table/tbody/tr[1]/td/input")));
                IWebElement captchaInput = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("codigo")));
                IWebElement captchaImage = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//table/tbody/tr/td[2]/img")));
                IWebElement sendButton   = waiter.Until(ExpectedConditions.ElementIsVisible(By.Id("botao_registo")));

                codeInput.SendKeys(code);

                ICaptchaSolver solver;
                if (decaptcher)
                {
                    solver = new DeathByCaptchaSolver();
                }
                else
                {
                    solver = new UserCaptchaSolver();
                }

                string base64captcha = captchaImage.GetAttribute("src");
                string captchaText   = solver.SolveBase64(base64captcha);

                if (string.IsNullOrWhiteSpace(captchaText))
                {
                    driver.Navigate().Refresh();
                    continue;
                }
                captchaInput.SendKeys(captchaText);

                sendButton.Click();

                try
                {
                    waiter.Until(driver =>
                    {
                        try
                        {
                            IWebElement nextPageText = driver.FindElement(By.XPath("//*[@class='t_verde' and contains(text(), 'Congratulations!')]"));
                            return(nextPageText.Displayed);
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            var errorCaptcha = driver.FindElement(By.XPath("//*[@id='form_registo']/div[2]/ul/li"));
                            throw new RegistrationException(new[] { "image" });
                        }
                        catch (RegistrationException)
                        {
                            throw;
                        }
                        catch (Exception)
                        {
                            return(false);
                        }
                    }); /// obsluga blednego captcha
                }
                catch (RegistrationException e) when(e.errors.Length == 1 && e.errors[0] == RegistrationException.RegistrationErrors.CaptchaError)
                {
                    solver.Report();
                    driver.Navigate().Refresh();
                    continue;
                }

                break;
            }
        }
Example #5
0
        public void BeginRegister(string firstname, string lastname, string login, string pass, string mailToConfirmation, string securityAnswer, bool deathByCaptcha = true)
        {
            driver.Navigate().GoToUrl("https://passport.yandex.com/registration/");
            WebDriverWait waiter        = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            IWebElement   NoPhoneButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[contains(@class, 'link_has-no-phone')]")));

            NoPhoneButton.Click();
            IWebElement firstnameElement     = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@for='firstname']/..")));
            IWebElement lastnameElement      = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@for='lastname']/..")));
            IWebElement loginElement         = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@for='login']/..")));
            IWebElement pass1Element         = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@for='password']/..")));
            IWebElement pass2Element         = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@for='password_confirm']/..")));
            IWebElement comboBoxVerification = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//span[@data-t='user-question-all']/span/button")));

            firstnameElement.BetterSendKeys(driver, firstname);
            lastnameElement.BetterSendKeys(driver, lastname);
            loginElement.BetterSendKeys(driver, login);
            pass1Element.BetterSendKeys(driver, pass);
            pass2Element.BetterSendKeys(driver, pass);
            comboBoxVerification.Click();

            Task.Delay(4000).Wait();

            var comboElements = driver.FindElements(By.XPath("//div[contains(@class, 'menu__item')]"));
            var idToClick     = new Random().Next(0, comboElements.Count - 1);

            comboElements[idToClick].Click();

            IWebElement answerElement = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@for='hint_answer']/..")));

            answerElement.BetterSendKeys(driver, securityAnswer);

            while (true)
            {
                IWebElement captchaInput        = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@for='captcha']/..")));
                IWebElement captchaImage        = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@class='captcha__image']")));
                IWebElement registerButton      = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//div[@class='form__submit']/button")));
                IWebElement changeCaptchaButton = waiter.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@class='captcha__reload']")));

                ICaptchaSolver solver;
                if (deathByCaptcha)
                {
                    solver = new DeathByCaptchaSolver();
                }
                else
                {
                    solver = new UserCaptchaSolver();
                }

                string code = solver.SolveUrl(captchaImage.GetAttribute("src"));
                if (string.IsNullOrEmpty(code))
                {
                    changeCaptchaButton.Click();
                    waiter.Until(ExpectedConditions.StalenessOf(captchaImage));
                    continue;
                }
                /// zrobic obsluge bledow
                captchaInput.BetterSendKeys(driver, code);
                registerButton.Click();

                IWebElement agreeButton = waiter.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[@class='eula-popup']//button")));
                agreeButton.Click();

                Func <IWebDriver, bool> watingForLoad = (driver) =>
                {
                    try
                    {
                        IWebElement nextPageText = driver.FindElement(By.XPath("//*[@class='personal-info__add-avatar d-link']"));
                        return(nextPageText.Displayed);
                    }
                    catch (Exception)
                    {
                    }

                    try
                    {
                        var errorCaptcha = driver.FindElement(By.XPath("//*[@class='error-message']"));
                        if (errorCaptcha.Text.Contains("The characters were entered incorrectly"))
                        {
                            throw new RegisterException(RegisterException.RegisterError.CaptchaError);
                        }
                        else
                        {
                            throw new RegisterException(RegisterException.RegisterError.AnotherError);
                        }
                    }
                    catch (RegisterException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                };
                try
                {
                    waiter.Until(watingForLoad);
                }
                catch (RegisterException e) when(e.error == RegisterException.RegisterError.CaptchaError)
                {
                    solver.Report(); /// przetestowac
                    continue;
                }

                break;
            }
        }