/// <summary> /// Navega até o chat do destinatário da mensagem /// </summary> /// <param name="recipient">Nome do detinatário no WhatsApp</param> private async Task NavigateToRecipientChat(string recipient) { IWebElement sidePane = new WebDriverWait(_webDriver, TimeSpan.FromDays(1)).Until(ExpectedConditions.ElementIsVisible(By.Id("pane-side"))); await Task.Delay(500); IWebElement targetChat = sidePane.FindElement(By.XPath($"//span[@title='{recipient}']")); targetChat.Click(); }
public BasePage ValidateAlertAfterAddingToFavorites(string expected_alert_msg = Constants.alert_add_favorites_en, int expected_amount = Constants.expected_amount_one_favorite) { IWebElement alert_dv = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(Constants.timeout)). Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id(Constants.alert_dv_id))); IWebElement alert_msg = alert_dv.FindElement(By.Id(Constants.alert_msg_id)); IWebElement alert_ok = alert_dv.FindElement(By.Id(Constants.alert_ok_id)); Assert.Equal(expected_alert_msg, alert_msg.Text); alert_ok.Click(); bool alert_dv_invisible = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(Constants.timeout)). Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.Id(Constants.alert_dv_id))); IWebElement mnu_fav_id = new WebDriverWait(_webDriver, TimeSpan.FromSeconds(Constants.timeout)). Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id(Constants.mnu_fav_id))); int curr_amount = Int32.Parse(Regex.Replace(mnu_fav_id.Text.Trim(), Constants.regex_brackets, "")); Assert.Equal(expected_amount, curr_amount); return(this); }
public void DownloadDataFile() { //easy to find Windows Documents path, a bit more work for Downloads (you'd think it would be easy eh?) //just find Documents, then replace with Downloads and concatenate csv filename string downloadsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).Replace("Documents", "Downloads"); string covidDataFilePath = Path.Combine(downloadsPath, QuebecPublicHealthCovidCasesWebPage.DownloadedCsvDataFilename); string renamedCovidDataFilename = Path.Combine(downloadsPath, "CovidDataFile." + DateTime.Now.ToString("yyyyMMdd-HHmm") + ".csv"); var chromeOptions = new ChromeOptions(); chromeOptions.AddArguments(new List <string>() { "headless" }); chromeOptions.AddArguments("--window-size=1024,1080"); //these are required to download files when using headless, this will behave more like a function call //if you want to see what the browser\Selenium is doing, you can comment the headless option part above chromeOptions.AddArguments(new List <string>() { "download.default_directory", downloadsPath }); chromeOptions.AddArguments("--disable-web-security"); chromeOptions.AddArguments("--allow-running-insecure-content"); //using this causes a problem with downloading the file, I'm not sure where it goes when Selenium is headless, //you might be able to explicitly set the download folder in ChromeOptions and then pick it up down below in the same path, //but I don't know where you will run this from, so I can't do this right now ChromeDriver driver = new ChromeDriver(chromeOptions); var settingForHeadlessDownloads = new Dictionary <string, object> { { "behavior", "allow" }, { "downloadPath", downloadsPath } }; driver.ExecuteChromeCommand("Page.setDownloadBehavior", settingForHeadlessDownloads); try { //goto the main page driver.Navigate().GoToUrl(QuebecPublicHealthCovidCasesWebPage.WebPageUrl); //scroll to the confirmed cases chart var confirmedCasesGraphElement = driver.FindElement(By.Id(QuebecPublicHealthCovidCasesWebPage.ConfirmedCasesGraphId)); ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", confirmedCasesGraphElement); //finding out when the data is finished dynamically loading new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementExists(By.XPath("//div[@id='evolutionHospitalisations']//*[name()='svg']"))); //click on the ellipsed to see the download csv option and click it IWebElement confirmedCasesGraphEllipse = driver.FindElement(By.XPath(QuebecPublicHealthCovidCasesWebPage.ConfirmedCasesGraphEllipseLocator)); confirmedCasesGraphEllipse.Click(); var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementExists(By.XPath(QuebecPublicHealthCovidCasesWebPage.DownloadCsvDataFile))); //IWebElement downloadCsvFile = WebDriverExtensions.FindElement(driver, By.XPath(QuebecPublicHealthCovidCasesWebPage.DownloadCsvDataFile), 30); IWebElement downloadCsvFile = wait.FindElement(By.XPath(QuebecPublicHealthCovidCasesWebPage.DownloadCsvDataFile)); downloadCsvFile.Click(); //before closing down the browser, lets give the file a bit of time to complete bool fileFound = DownloadDataFile(covidDataFilePath); ReportDataDownladStatus(covidDataFilePath, renamedCovidDataFilename, fileFound); } finally { Console.WriteLine("Just a sec...closing Selenium Chrome web driver is slow, but it should close everything"); driver.Close(); driver.Dispose(); driver.Quit(); } }