private void CheckStatus() { maxIdChecking = -1; var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60)); wait.Until(ExpectedConditions.ElementIsVisible(By.ClassName("scroll-area"))); IWebElement scrollPanel = driver.FindElement(By.ClassName("scroll-area")); wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60)); wait.Until(ExpectedConditions.ElementIsVisible(By.TagName("tr"))); var webElements = scrollPanel.FindElements(By.TagName("tr")); for (int i = webElements.Count - 1; i >= 0; i--) { var data = webElements[i].FindElements(By.TagName("td")); string text = $"{data[1].Text} $ $".Split(' ')[1]; var isDocumentInQueue = checking.Where(d => d.Contains(text)).FirstOrDefault(); if (isDocumentInQueue != null) { maxIdChecking = Math.Max(maxIdChecking, i); IWebElement IsDucumentChecked = null; try { IsDucumentChecked = webElements[i].FindElements(By.ClassName("report-link")).FirstOrDefault(); } catch (StaleElementReferenceException ex) { continue; } if (IsDucumentChecked != null) { logger.LogInformation(AppData.Strings.Reply); string reportPath = DownloadReport(webElements[i]); checking.Remove(isDocumentInQueue); OnDocumentChecked?.Invoke(this, isDocumentInQueue, reportPath); driver.Navigate().GoToUrl("https://users.antiplagiat.ru/cabinet"); break; } } } }
public void Run(CancellationToken token) { driver = InitDriwer(); logger.LogInformation(AppData.Strings.AuthorizeAntiplagiat); driver.Url = $"{credentials.Base}/cabinet"; driver.Navigate(); IWebElement loginButton = driver.FindElements(By.ClassName("enter")).FirstOrDefault(); if (loginButton != null) { loginButton = loginButton.FindElements(By.TagName("a")).FirstOrDefault(); } if (loginButton != null) { loginButton.Click(); Task.Delay(100).Wait(); IWebElement emailTextbox = driver.FindElement(By.ClassName("email")).FindElement(By.TagName("input")); IWebElement passwordTextBox = driver.FindElement(By.ClassName("passwd")).FindElement(By.TagName("input")); IWebElement enterButton = driver.FindElement(By.Id("login-button")); emailTextbox.SendKeys(credentials.Login); Task.Delay(100).Wait(); passwordTextBox.SendKeys(credentials.Password); Task.Delay(100).Wait(); enterButton.Click(); } logger.LogInformation(AppData.Strings.TryAuthorizeAntiplagiat); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60)); wait.Until(ExpectedConditions.ElementIsVisible(By.Id("add-document"))); logger.LogInformation(AppData.Strings.AuthorizeAntiplagiatSuccess); while (!token.IsCancellationRequested) { logger.LogInformation($"{AppData.Strings.Checking} ({documentsQueue.Count}) ({checking.Count})"); while (documentsQueue.Any() && maxIdChecking < 10) { string path = documentsQueue.Peek(); logger.LogInformation($"{AppData.Strings.Upload} {path}"); UploadDocument(path); documentsQueue.Dequeue(); maxIdChecking++; } if (checking.Any()) { CheckStatus(); if (maxIdChecking < 0) { foreach (var x in checking) { OnDocumentChecked?.Invoke(this, x, string.Empty); } checking.Clear(); } } else { maxIdChecking = -1; } Task.Delay(1000).Wait(); } }