public override bool Auth(FirefoxDriver driver, string login, string password) { SendMessage($"Auth => Start from {login}"); WaitExecute(driver); Find(driver, "a", "data-marker", "header/login-button", e => JsClick(driver, e)); WaitPage(driver, 30000, "Войти"); SendMessage($"Auth => Click from Enter"); WaitExecute(driver); var authResult = false; var exceptionRegistrationFail = "Неправильная пара логин"; var exceptionStrings = new string[] { "Неправильная пара логин", "Некорректный номер телефона", "Личный кабинет", "Доступ заблокирован", "Текст с картинки" }; for (int i = 0; i < 30; i++) { Find(driver, "input", "data-marker", "login-form/login", e => { e.Clear(); e.SendKeys(login); }); Find(driver, "input", "data-marker", "login-form/password", e => { e.Clear(); e.SendKeys(password); }); if (HasContains(driver, "div", "class", "captcha-root")) { var capcha = ""; var capchaPath = ""; FindContains(driver, "div", "class", "captcha-image", e => { capchaPath = GetScreenshotElementWithOffset(driver, e, login, new System.Drawing.Point(-1, -e.Size.Height - 5)); }); capcha = FreegateHelper.ImageToText(capchaPath); DoAction(driver, By.CssSelector($"input[placeholder='Текст с картинки']"), e => { e.Clear(); e.SendKeys(capcha); }); } Find(driver, "button", "data-marker", "login-form/submit", e => JsClick(driver, e)); WaitPage(driver, 30000, exceptionStrings); authResult = driver.Title.Contains("Личный кабинет"); if (authResult) { break; } if (driver.PageSource.Contains(exceptionRegistrationFail)) { break; } Thread.Sleep(2000); } SendMessage($"Auth => Complete, auth is {authResult}"); if (authResult) { return(true); } foreach (var str in exceptionStrings) { if (driver.PageSource.Contains(str)) { SendMessage($"Auth => Error - {str}"); } } return(false); }
public override AccessCache Registration(FirefoxDriver driver, AccessCache access) { var result = access; DCT.Execute(c => { var tzid = -1; if (access.IsForwarding) { SendMessage($"Registration => Wait ForwardNumber"); tzid = OnlineSimHelper.GetForward(forwardNumber).tzid; } else { SendMessage($"Registration => Wait Number"); tzid = OnlineSimHelper.GetNum(ServiceType.avito).tzid; } SendMessage($"Registration => tzid: {tzid}"); var getState = OnlineSimHelper.GetState(tzid); if (getState == null) { SendMessage($"Registration => GetState is null. Abort operation"); return; } access.Phone = getState.number; access.PhoneTZID = getState.tzid; SendMessage($"Registration => Phone: {access.Phone}"); WaitExecute(driver); //Перехожу в регистрацию driver.Navigate().GoToUrl("https://www.avito.ru/registration"); WaitExecute(driver); //Заполняю все поля DoAction(driver, By.CssSelector($"input[name='name']"), e => { e.Clear(); e.SendKeys("Валера"); }); DoAction(driver, By.CssSelector($"input[name='email']"), e => { e.Clear(); e.SendKeys(access.Login); }); var phone = access.Phone.Replace("+7", ""); DoAction(driver, By.CssSelector($"input[name='phone']"), e => { e.Clear(); e.SendKeys(phone); }); for (int i = 0; i < 30; i++) { DoAction(driver, By.CssSelector($"input[name='password']"), e => { e.Clear(); e.SendKeys(access.Password); }); var capcha = ""; var capchaPath = ""; Find(driver, "img", "class", "form-captcha-image js-form-captcha-image", e => { capchaPath = GetScreenshotElement(driver, e, access.Login); }); capcha = FreegateHelper.ImageToText(capchaPath); DoAction(driver, By.CssSelector($"input[name='captcha']"), e => { e.Clear(); e.SendKeys(capcha); }); FindTagByTextContains(driver, "button", "Зарегистрироваться", x => JsClick(driver, x)); Thread.Sleep(2000); if (driver.PageSource.Contains("Регистрация. Шаг 2")) { break; } } if (!driver.PageSource.Contains("Регистрация. Шаг 2")) { SendMessage("Registration => Captcha is not resolved"); AccessHelper.Disable(access.Id); return; } Find(driver, "button", "class", "button button-azure js-phone-checker-request-code", x => JsClick(driver, x)); for (int i = 0; i < 30; i++) { Thread.Sleep(3000); var state = getState = OnlineSimHelper.GetState(tzid); SendMessage($"Registration => Wait SMS, state = {state.response}"); if (state.responseEnum == getStateState.TZ_NUM_ANSWER) { DoAction(driver, By.CssSelector($"input[id='phone-checker-code']"), e => { e.Clear(); e.SendKeys(state.msg); }); break; } } Find(driver, "button", "class", "button button-origin button-origin_large button-origin-green js-registration-form-submit", x => JsClick(driver, x)); //Получаю смску Thread.Sleep(2000); //Подтверждаю AccessHelper.Enable(access.Id); }); return(access); }