Пример #1
0
 protected static bool IsElementVisible(PageElement pageElement, TimeSpan?maxWaitTime = null)
 {
     pageElement.GoToFrame();
     return(SeleniumUtility
            .WebDriverWait(ExpectedConditions.ElementIsVisible(pageElement.Locator), maxWaitTime ?? Default5Seconds)
            .Displayed);
 }
Пример #2
0
 protected static void Click(PageElement pageElement, TimeSpan?maxWaitTime = null)
 {
     pageElement.GoToFrame();
     SeleniumUtility
     .WebDriverWait(
         ExpectedConditions.ElementToBeClickable(SeleniumDriver.Driver.FindElement(pageElement.Locator)),
         maxWaitTime).Click();
 }
Пример #3
0
        protected static void RightClick(PageElement pageElement, TimeSpan?maxWaitTime = null)
        {
            pageElement.GoToFrame();
            var actions =
                new OpenQA.Selenium.Interactions.Actions(SeleniumDriver.Driver);

            actions.ContextClick(SeleniumUtility.WebDriverWait(ExpectedConditions.ElementIsVisible(pageElement.Locator),
                                                               maxWaitTime ?? Default5Seconds)).Build().Perform();
        }
Пример #4
0
 protected static void ClickMultipleElements(PageElement pageElement)
 {
     pageElement.GoToFrame();
     foreach (var element in SeleniumDriver.Driver.FindElements(pageElement.Locator))
     {
         SeleniumUtility.WebDriverWait(ExpectedConditions.ElementToBeClickable(element), Default5Seconds)
         .Click();
     }
 }
Пример #5
0
        protected static void Type(PageElement pageElement, string input)
        {
            pageElement.GoToFrame();
            var element =
                SeleniumUtility.WebDriverWait(ExpectedConditions.ElementToBeClickable(pageElement.Locator));

            element.Clear();
            element.SendKeys(input);//

            Assert.AreEqual(input, ExtractText(pageElement, Default5Seconds));
        }
Пример #6
0
        private string WaitForElementToDisplay(int index, TimeSpan?maxWaitTime = null)
        {
            var locator = $"{this}{AddIndex(index)}";

            if (SeleniumUtility.WebDriverWait(driver => driver.ExecuteJavaScript <string>(locator).IsBlank(),
                                              maxWaitTime ?? Default5Seconds))
            {
                throw new NotFoundException($"Did not find element within {maxWaitTime ?? Default5Seconds}: {locator}");
            }

            return(locator);
        }
Пример #7
0
 private void scrapeButton_Click(object sender, EventArgs e)
 {
     foreach (var site in sites)
     {
         Task.Run(async() =>
         {
             var driver = SeleniumUtility.CreateDefaultFirefoxDriver();
             activeDrivers.TryAdd(site.SiteName, driver);
             await site.ScrapeAsync(driver);
             lock (lockObj)
             {
                 driver.Quit();
             }
             activeDrivers.TryRemove(site.SiteName, out driver);
         });
     }
 }
Пример #8
0
        protected static string ExtractText(PageElement pageElement, TimeSpan?maxWaitTime)
        {
            try
            {
                pageElement.GoToFrame();
                var element = SeleniumUtility.WebDriverWait(
                    ExpectedConditions.ElementIsVisible(pageElement.Locator),
                    maxWaitTime ?? Default5Seconds);

                var text = GetTextByType(pageElement.ElementType, element);

                if (text == null)
                {
                    throw new NotFoundException($"{TextNotFound} Element: {pageElement}");
                }

                return(text);
            }
            catch (Exception e)
            {
                throw new NotFoundException($"Error getting value: {e.StackTrace}");
            }
        }
Пример #9
0
 private void CurrentOnExit(object sender, ExitEventArgs exitEventArgs)
 {
     SeleniumUtility.KillSeleniumProcesses(DriverService.ProcessId);
 }
Пример #10
0
 protected static bool IsElementNotVisible(PageElement pageElement, TimeSpan?maxWaitTime = null)
 {
     pageElement.GoToFrame();
     return(SeleniumUtility.WebDriverWait(ExpectedConditions.InvisibilityOfElementLocated(pageElement.Locator),
                                          maxWaitTime ?? Default5Seconds));
 }
Пример #11
0
 public static IWebDriver SwitchToFrame(string name, TimeSpan?maxWaitTime)
 {
     return(SeleniumUtility.WebDriverWait(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(name), maxWaitTime));
 }