Example #1
0
        public void DynamicWait(IWebElement element)
        {
            WebDriverWait wait = new WebDriverWait(ObjectRepository.Driver, TimeSpan.FromSeconds(120));

            wait.PollingInterval = TimeSpan.FromMilliseconds(100);
            wait.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(ElementNotVisibleException));
            wait.Until(ExpectedConditions.ElementSelectionStateToBe(element, true));
        }
Example #2
0
        public ReadOnlyCollection <IWebElement> DownloadTimbratureCurrentMonth(string user, string pwd, DateTime targetDate, TimbratureBuilder builder, System.ComponentModel.BackgroundWorker worker)
        {
#pragma warning disable CS0618 // Type or member is obsolete
            wait.Until(ExpectedConditions.ElementExists(By.Name("m_cUserName")));
            wait.Until(ExpectedConditions.ElementExists(By.Name("m_cPassword")));
            wait.Until(ExpectedConditions.ElementExists(By.CssSelector("input[class='buttonlogin Accedi_ctrl']")));

            try
            {
                worker.ReportProgress(5);
                // LOGIN
                driver.FindElement(By.Name("m_cUserName")).SendKeys(user);
                driver.FindElement(By.Name("m_cPassword")).SendKeys(pwd);

                driver.FindElement(By.CssSelector("input[class='buttonlogin Accedi_ctrl']")).Click();

                // TIMBRATURE

                wait.Until(ExpectedConditions.ElementExists(By.CssSelector("td[class='grid_title grid_cell_title']")));
                worker.ReportProgress(40);

                String          tableId = driver.FindElement(By.ClassName("hfpr_wcartellino2c_container")).GetAttribute("id");
                Regex           rx      = new Regex(@"^(.*?)_container", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                MatchCollection matches = rx.Matches(tableId);
                if (matches.Count > 0)
                {
                    ReadOnlyCollectionBuilder <IWebElement> collection = new ReadOnlyCollectionBuilder <IWebElement>(5);
                    String   randomId         = matches[0].Groups[1].Value;
                    DateTime currentPageMonth = DateTime.Now;
                    DateTime firstDayNumber   = Utils.getFirstWorkingDayOfWeekAsDate(targetDate);//todo check if first day is previous month
                    DateTime currDay          = firstDayNumber;
                    bool     bNewMonth        = false;
                    for (int i = 0; i < 5; ++i)
                    {
                        currDay   = firstDayNumber.AddDays(i);
                        bNewMonth = currDay.Month != currentPageMonth.Month;
                        if (!bNewMonth)
                        {
                            IWebElement elem = driver.FindElement(By.Id(randomId + "_Grid1_row" + (currDay.Day - 1)));
                            builder.addDate(elem, currDay.DayOfWeek);
                            collection.Add(elem);
                            worker.ReportProgress(52 + i * 12);
                        }
                        else
                        {
                            IWebElement currMonth = new SelectElement(driver.FindElement(By.ClassName("TxtMese_ctrl"))).SelectedOption;
                            if ((currDay.Month < currentPageMonth.Month && currDay.Year == currentPageMonth.Year) || currDay.Year < currentPageMonth.Year)
                            {
                                driver.FindElement(By.ClassName("BtnMesePrev_ctrl")).Click();
                                currentPageMonth = currentPageMonth.AddMonths(-1);
                            }
                            else
                            {
                                driver.FindElement(By.ClassName("BtnMeseNext_ctrl")).Click();
                                currentPageMonth = currentPageMonth.AddMonths(1);
                            }

                            wait.Until(ExpectedConditions.ElementSelectionStateToBe(currMonth, false));
                            wait.Until(ExpectedConditions.ElementExists(By.CssSelector("td[class='grid_title grid_cell_title']")));
                            i--;//redo current loop, we changed month
                        }
                    }
                    return(collection.ToReadOnlyCollection());
                }
                else
                {
                    //ReadOnlyCollection<IWebElement> selected = driver.FindElements(By.CssSelector("tr[class='grid_row grid_rowselected']")); // WTF ZUCCHETTI
                    ReadOnlyCollection <IWebElement> selected = driver.FindElements(By.XPath("//*[@class='grid_row grid_rowselected']"));           // WTF ZUCCHETTI

                    ReadOnlyCollection <IWebElement> selectedOdd = driver.FindElements(By.CssSelector("tr[class='grid_rowodd grid_rowselected']")); // WTF ZUCCHETTI

                    ReadOnlyCollection <IWebElement> pairRowsRO = driver.FindElements(By.XPath("//*[@class='grid_row']"));                          // REALLYYY. ZUCCHETTI PLZ
                    ReadOnlyCollection <IWebElement> oddRowsRO  = driver.FindElements(By.XPath("//*[@class='grid_rowodd']"));                       // REALLYYY. ZUCCHETTI PLZ

                    return(new ReadOnlyCollectionBuilder <IWebElement>(pairRowsRO.Concat(oddRowsRO)
                                                                       .Concat(selectedOdd)
                                                                       .Concat(selected))
                           .ToReadOnlyCollection());
                }
            }
            catch
            {
            }

            return(new ReadOnlyCollectionBuilder <IWebElement>().ToReadOnlyCollection());

#pragma warning restore CS0618 // Type or member is obsolete
        }
Example #3
0
 /// <summary>
 /// Waits for the selection of an element to reach a certain state
 /// </summary>
 /// <param name="element">The IWebElement to await</param>
 /// <param name="state">The selection state to check for</param>
 /// <returns>True if the wait is terminated by the element being found to be in a given selection state.</returns>
 public bool WaitForElementSelectionStateToBe(IWebElement element, bool state)
 {
     try
     {
         var wait = new WebDriverWait(Driver, Preferences.BaseSettings.Timeout).Until(ExpectedConditions.ElementSelectionStateToBe(element, state));
         if (wait == false)
         {
             throw new Exception("Could not confirm selection state of the element required.");
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #4
0
        public static void WaitForSelectionStateToBe(this By by, bool selected, int timeoutInSeconds = 30)
        {
            var wait = new WebDriverWait(BaseSeleniumPage.webDriver, TimeSpan.FromSeconds(timeoutInSeconds));

            wait.Until(ExpectedConditions.ElementSelectionStateToBe(by, selected));
        }
 public bool WaitForElementSelectionStateToBe(IWebDriver driver, IWebElement element, bool selected)
 {
     return(new WebDriverWait(driver, seconds).Until(
                ExpectedConditions.ElementSelectionStateToBe(element, selected)));
 }
Example #6
0
        public static bool WaitingFor_ElementSelectionStateToBe(IWebDriver driver, By locator, bool selected, TimeSpan timeOut)
        {
            var wait = new WebDriverWait(driver, timeOut);

            return(wait.Until(ExpectedConditions.ElementSelectionStateToBe(locator, selected)));
        }