public override void Vote(IVoteContext ctx) { int attempts = 0; start: if (++attempts > MaxLoops) { throw new Exception("Too many loops. Is it an authorization bug?"); } RemoteWebDriver driver = ctx.Driver; driver.Url = Url; //=== open voting modal window ctx.Log("Opening modal"); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3); driver.FindElement(By.CssSelector(".openLoginModal, .openVoteModal")).Click(); ctx.Log("Performing modal checks"); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3); IWebElement elem = driver.FindElements(By.CssSelector(".modalVkLogin")).FirstOrDefault(); if (elem == null) { ctx.Log("Voting for {0}", ctx.Nickname); driver.FindElement(By.CssSelector("#nick")).Clear(); driver.FindElement(By.CssSelector("#nick")).SendKeys(ctx.Nickname); driver.FindElement(By.CssSelector(".voteBtn")).Click(); ctx.Log("Validating"); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); if (driver.FindElement(By.CssSelector(".tooltip-inner")).Text == "Сегодня Вы уже голосовали") { throw new AbortException("Already voted! ^.^"); } } else { ctx.Log("Authorizing"); //manually navigating because button not seems to be working driver.Url = new Uri(new Uri(new Uri(driver.Url).GetLeftPart(UriPartial.Authority)), @"/accounts/vk/login/?process=login").ToString(); Utilities.CheckVKUserAuth(ctx); goto start; //releasing the satan from hell } }
public static void CheckVKUserAuth(IVoteContext ctx) { ctx.Log("Waiting user for authorization"); new WebDriverWait(ctx.Driver, TimeSpan.FromMinutes(1.2f)) .Until((d) => new Uri(d.Url).Host.ToLower() != "oauth.vk.com"); }
public abstract void Vote(IVoteContext context);
public override void Vote(IVoteContext ctx) { int attempts = 0; start: if (++attempts > MaxLoops) { throw new Exception("Too many loops! Is it a timer bug?"); } RemoteWebDriver driver = ctx.Driver; driver.Url = $"http://mcrate.su/project/{ProjectId}"; ctx.Log("Opening auth page"); driver.FindElement(By.CssSelector(".fa-thumbs-o-up")).Click(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); ctx.Log("Authorizing"); driver.FindElement(By.CssSelector(".vk_authorization")).Click(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); Utilities.CheckVKUserAuth(ctx); ctx.Log("Performing checks"); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(3); IWebElement elem = driver.FindElements(By.Name("login_player")).FirstOrDefault(); if (elem == null) { TimeSpan span = TimeSpan.MinValue; try { Thread.Sleep(1300); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10); int h = int.Parse(driver.FindElement(By.CssSelector(".timer_count .count_hour")).Text); int m = int.Parse(driver.FindElement(By.CssSelector(".timer_count .count_min")).Text); int s = int.Parse(driver.FindElement(By.CssSelector(".timer_count .count_sec")).Text); span = new TimeSpan(h, m, s); } catch (Exception) { } if (span < LoopbackThreshold) { goto start; //... } if (span.Ticks <= 0) { throw new AbortException("Already voted! ^.^"); } else { throw new AbortException("Already voted! ^.^ Please wait for " + StringUtils.GetTimeString(span) + "."); } } ctx.Log("Voting for {0}", ctx.Nickname); elem.Clear(); elem.SendKeys(ctx.Nickname); driver.FindElement(By.CssSelector("#buttonrate")).Click(); Thread.Sleep(5000); //TODO replace }