Exemplo n.º 1
2
        /// <summary>
        /// Finds the elements with timeout wait.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="by">The by.</param>
        /// <returns></returns>
        public static ReadOnlyCollection<IWebElement> FindElementsWithTimeoutWait(IWebDriver driver, By by)
        {
            Exception ex = null;
            ReadOnlyCollection<IWebElement> e = null;
            long elapsedTime = 0;
            while (elapsedTime < TimeOut)
            {
                try
                {
                    elapsedTime++;
                    StandardSleep(1);
                    e = driver.FindElements(by);
                    break;
                }
                catch (NoSuchElementException nse)
                {
                    if (e == null)
                        throw ex;
                }
            }

            if (e == null)
                throw ex;

            return e;
        }
 public static void AssertElementPresent(ISearchContext context, By searchBy, string elementDescription)
 {
     if (!IsElementPresent(context, searchBy))
     {
         throw new AssertionException(String.Format("AssertElementPresent Failed: Could not find '{0}'", elementDescription));
     }
 }
Exemplo n.º 3
0
    public static IEnumerable<IWebElement> WaitUntilElementsInvisible(this IWebDriver driver, By selector)
    {
      var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
      wait.Until(ExpectedConditions.InvisibilityOfElementLocated(selector));

      return driver.FindElements(selector);
    }
Exemplo n.º 4
0
 public static IWebElement GetElement(By locator)
 {
     if (IsElemetPresent(locator))
         return ObjectRepository.Driver.FindElement(locator);
     else
         throw new NoSuchElementException("Element Not Found : " + locator.ToString());
 }
Exemplo n.º 5
0
 /// <summary>
 /// Construct an element
 /// </summary>
 /// <param name="locator">By locator</param>
 public Element(By locator): base()
 {
     this.name = "Element";
     this.by = locator;
     this.pageObjectName = TestBase.GetCurrentClassName();
     this.timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec;
 }
Exemplo n.º 6
0
 /// <summary>
 ///     Construct an element
 /// </summary>
 /// <param name="locator">By locator</param>
 public Element(By locator)
 {
     name = "Element";
     by = locator;
     pageObjectName = TestBase.GetCurrentClassName();
     timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec;
 }
Exemplo n.º 7
0
 /// <summary>
 ///     Construct an element
 /// </summary>
 /// <param name="name">Human readable name of the element</param>
 /// <param name="locator">By locator</param>
 public Element(string name, By locator)
 {
     this.name = name;
     by = locator;
     pageObjectName = TestBase.GetCurrentClassName();
     timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec;
 }
Exemplo n.º 8
0
 /// <summary>
 ///     Construct an element using an existing element
 /// </summary>
 /// <param name="element"></param>
 public Element(IWebElement element, By by)
 {
     this.element = element;
     this.by = by;
     pageObjectName = TestBase.GetCurrentClassName();
     timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec;
 }
Exemplo n.º 9
0
		public SlidingSelect(IWebDriver driver, By arrowId, By listDropDownId)
		{
			_driver = driver;

			_arrowId = arrowId;
			_listDropDownId = listDropDownId;
		}
Exemplo n.º 10
0
        public static void CreateNewPortal(IWebDriver driver, string portalName, By template)
        {
            Login.AsHost(driver);

            driver.Navigate().GoToUrl(SiteManagementPage);

            driver.WaitClick(CreatePortalButton);

            driver.WaitClick(AddSiteSiteTypeChildRadio);

            driver.FindDnnElement(AddSitePortalAliasTextbox).Clear();

            driver.WaitSendKeys(AddSitePortalAliasTextbox, "localhost/DotNetNuke_Enterprise/" + portalName + "/");

            driver.FindDnnElement(AddSitePortalAliasTextbox).Clear();

            driver.WaitSendKeys(AddSitePortalAliasTextbox, "localhost/DotNetNuke_Enterprise/" + portalName + "/");

            driver.WaitSendKeys(AddSitePortalNameTextbox, portalName);

            driver.WaitClick(AddSiteTemplateInput);
            driver.WaitClick(template);

            driver.WaitClick(AddSiteCreateSiteButton);

            int origTimeout = Common.DriverTimeout;
            Common.DriverTimeout = 30000;
            driver.WaitClick(AddSiteVisitNewPortalLink);
            Common.DriverTimeout = origTimeout;
        }
Exemplo n.º 11
0
 public static string GetButtonText(By locator)
 {
     element = GenericHelper.GetElement(locator);
     if (element.GetAttribute("value") == null)
         return String.Empty;
     return element.GetAttribute("value");
 }
 public static void ScrollElementAndClick(By locator)
 {
     IWebElement element = ObjectRepository.Driver.FindElement(locator);
     GenericHelper.WaitForElement(element);
     ExecuteScript("window.scrollTo(0," + element.Location.Y + ");");
     element.Click();
 }
Exemplo n.º 13
0
        protected IWebElement waitForElementAndReturn(By selector)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.Until(drv => driver.FindElement(selector) != null);

            return driver.FindElement(selector);
        }
 public static IWebElement WaitElementIsRendered(this IWebDriver driver, By selector)
 {
     return Wait.Until(Timeouts.Default,
         () => FindElement(driver, selector),
         element => element != null && element.Displayed,
         $"Element with selector:{selector} could not be rendered");
 }
 public static string WaitTextIsRendered(this IWebDriver driver, By elementSelector)
 {
     return Wait.Until(Timeouts.Default,
         () => FindElement(driver, elementSelector)?.Text,
         text => !string.IsNullOrEmpty(text),
         $"Element with selector:{elementSelector} could not be rendered");
 }
Exemplo n.º 16
0
 public static void ScrollToAndClick(By locator)
 {
     IWebElement element = GenericHelper.GetElement(locator);
     ExecuteScript("window.scrollTo(0," + element.Location.Y + ")");
     Thread.Sleep(300);
     element.Click();
 }
 public void Selectanoption(IWebDriver driver, By by, string optiontoselect)
 {
     var data = driver.FindElement(@by);
     //IList<IWebElement> dataoptions = data.FindElements(By.TagName("option"));
     var select = new SelectElement(data);
     @select.SelectByText(optiontoselect);
 }
Exemplo n.º 18
0
        public static bool ElementIsDisplayed(this IWebDriver driver, By by)
        {
            System.Threading.Thread.Sleep(5);
            IWebElement el;
            bool isDisplayed = false;
            bool gotBoolean;

            if (driver.ElementExists(by))
            {
                el = driver.FindElement(by);
                do
                {
                    // For whatever reason, on Android this often throws an InvalidCastException
                    try
                    {
                        isDisplayed = el.Displayed;
                        gotBoolean = true;
                    } catch (InvalidCastException)
                    {
                        // Loop until we get either a true or false
                        gotBoolean = false;
                    }
                } while (gotBoolean == false);
                return isDisplayed;
            }
            else
            {
                return false;
            }
        }
Exemplo n.º 19
0
    public static IEnumerable<IWebElement> WaitUntilElementsPresent(this IWebDriver driver, By selector)
    {
      var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
      wait.Until(ExpectedConditions.ElementExists(selector));

      return driver.FindElements(selector);
    }
Exemplo n.º 20
0
 public ByAttribute(By by, string attributeName, string attributeValue, Func<string, string, bool> attrComparisonMethod, Input input = Input.Type, bool visibleOnly = true)
     : base(by, input, visibleOnly)
 {
     Attributes = new Dictionary<string, string>();
     Attributes.Add(attributeName, attributeValue);
     ComparisonMethod = attrComparisonMethod;
 }
Exemplo n.º 21
0
        public Element(string element)
        {
            if (string.IsNullOrEmpty(element))
                return;

            // assume XPath expression
            if (element.Contains("/"))
            {
                this.element = By.XPath(element);
                return;
            }

            var token = element.Split('=');
            if (token.Length != 2)
                return;

            var key = token[0].Trim().ToLower();
            var value = token[1].Trim();

            if ("id".Equals(key))
            {
                this.element = By.Id(value);
            }
            else if ("name".Equals(key))
            {
                this.element = By.Name(value);
            }
            else if ("link".Equals(key))
            {
                this.element = By.LinkText(value);
            }
        }
Exemplo n.º 22
0
 public void WaitForElementPresentAndEnabled(By locator, int secondsToWait = 30)
 {
     new WebDriverWait(this.driver, new TimeSpan(0, 0, secondsToWait))
        .Until(d => d.FindElement(locator).Enabled
            && d.FindElement(locator).Displayed
        );
 }
 protected PageElement(By byLocator)
 {
     BaseElement = new CCElement(byLocator);
     if (ValidTags != null && !ValidTags.Contains(BaseElement.TagName.ToLower())) {
         throw new Exception("Tag '" + BaseElement.TagName + "' is not valid");
     }
 }
Exemplo n.º 24
0
        public static IWebElement WaitForElementEx(this ISearchContext node, By condition, int? maxWaitMS = null, int? waitIntervalMS = null)
        {
            maxWaitMS = maxWaitMS ?? MaxWaitMS;
            waitIntervalMS = waitIntervalMS ?? WaitIntervalMS;

            DateTime finishTime = DateTime.UtcNow.AddMilliseconds(maxWaitMS.Value);

            do
            {
                DateTime timeAttempted = DateTime.UtcNow;
                try
                {
                    return node.FindElement(condition);
                }
                catch (Exception)
                {
                    if (timeAttempted > finishTime)
                    {
                        throw;
                    }
                }

                Thread.Sleep(waitIntervalMS.Value);
            } while (true);
        }
Exemplo n.º 25
0
 public static IWebElement FindDisplayedElement(this IWebDriver webDriver, By by, double time)
 {
     try
     {
         {
             return new WebDriverWait(webDriver, TimeSpan.FromSeconds(time))
                 .Until<IWebElement>(d =>
                 {
                     try
                     {
                         return d.FindElement(@by).Displayed ? d.FindElement(@by) : null;
                     }
                     catch (Exception)
                     {
                         return null;
                     }
                 });
         }
     }
     catch (WebDriverTimeoutException)
     {
         Console.WriteLine("Element was not found. Timeou after: {0}", time);
         return null;
     }
 }
        private IEnumerable<INativeElement> FindElements(By by)
        {
            var elements = _context.FindElements(by);
            foreach (var element in elements)
                yield return new WebDriverNativeElement(element);

        }
Exemplo n.º 27
0
        public IWebElement GetElement(By by)
        {
            if (Tag == null)
                throw new NullReferenceException("You can't call GetElement on a block without first initializing Tag.");

            return Tag.GetElement(by);
        }
Exemplo n.º 28
0
        public IList<IWebElement> GetElements(By by)
        {
            if (Tag == null)
                throw new NullReferenceException("You can't call GetElements on a block without first initializing Tag.");

            return Tag.FindElements(by);
        }
Exemplo n.º 29
0
 public ScrollElement(ScrollerItems item)
 {
     ImageDropName = itemsdrop[item];
     ImageDragName = itemsdrag[item];
     locator = itempath[item];
     var wait = new WebDriverWait(Browser.GetDriver(), TimeSpan.FromMilliseconds(Convert.ToDouble(Configuration.GetTimeout())));
     try
     {
         wait.Until(waiting =>
         {
             try
             {
                 return Browser.GetDriver().FindElement(locator).GetAttribute("style").Contains("background-image: url");
             }
             catch (Exception)
             {
                 return false;
             }
         });
     }
     catch (WebDriverTimeoutException)
     {
         Assert.Fail("Cannot wait until image displayed");
     }
 }
 public override void setupDev1()
 {
     txtSearch = By.Id("gbqfq");
     btnSearch1 = By.Id("gbqfba");
     btnSearch2 = By.Id("gbqfb");
     lnkAny = By.XPath(".//*[@id='rso']//a[1]");
 }
Exemplo n.º 31
0
        /// <summary>
        /// Click the 'Open Vavancy' link that appears after clicking a vacancy record in the search results
        /// </summary>
        private void OpenVacancy()
        {
            var openVacancyLink = _driver.FindElement(By.LinkText("Show Applicants"));

            openVacancyLink.WaitAndClick(_driver);
        }
Exemplo n.º 32
0
        /// <summary>
        /// Click the 'Open Application' link that appears after clicking an applicant record in the search results
        /// </summary>
        private void OpenApplication()
        {
            var openApplicationLink = _driver.FindElement(By.LinkText("Open Application"));

            openApplicationLink.WaitAndClick(_driver);
        }
Exemplo n.º 33
0
 public ReadOnlyCollection <IWebElement> FindElements(By @by)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 34
0
        /// <summary>
        /// Finds the first <see cref="OpenQA.Selenium.IWebElement" /> using the specified method.
        /// </summary>
        /// <param name="by">The locating mechanism to use.</param>
        /// <returns>The first matching <see cref="OpenQA.Selenium.IWebElement" /> on the current context.</returns>
        /// <exception cref="OpenQA.Selenium.NoSuchElementException">If no element matches the criteria.</exception>
        public virtual IWebElement FindElement(OpenQA.Selenium.By by)
        {
            long implictWait = GetImplicitWait();

            return(FindElement(by, implictWait));
        }
Exemplo n.º 35
0
        /// <summary>
        /// Finds a widget relative to the current one by traversing the qooxdoo
        /// widget hierarchy.
        /// </summary>
        /// <param name="by">The locating mechanism to use.</param>
        /// <returns>The found widget.</returns>
        public virtual IWidget FindWidget(OpenQA.Selenium.By by)
        {
            IWebElement element = FindElement(by);

            return(Driver.GetWidgetForElement(element));
        }
 public static IList <Footer> Footers(this ISearchContext context, OpenQA.Selenium.By constraint = null)
 {
     return(context.Find <Footer>(constraint));
 }
Exemplo n.º 37
0
 public IWebElement FindNonExistentElement(int timeoutInSeconds)
 {
     return(Find().Element(By.Id("RandomElement"), TimeSpan.FromSeconds(timeoutInSeconds)));
 }
Exemplo n.º 38
0
        /// <summary>
        /// Click the 'Open Employee Record' link that appears after clicking an employee record in the search results
        /// </summary>
        private void OpenEmployeeRecord()
        {
            var openEmployeeRecordLink = _driver.FindElement(By.LinkText("Open Employee Record"));

            openEmployeeRecordLink.WaitAndClick(_driver);
        }
Exemplo n.º 39
0
 /// <summary>
 /// Common method for click functionality.
 /// </summary>
 /// <param name="Locator">Element to perform action on.</param>
 public static void clickElement(OpenQA.Selenium.By Locator)
 {
     CommonProperties.commonDriver.FindElement(Locator).Click();
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:OpenQA.Selenium.Support.Events.FindElementEventArgs" /> class.
 /// </summary>
 /// <param name="driver">The WebDriver instance used in finding elements.</param>
 /// <param name="element">The element that was found</param>
 /// <param name="method">The <see cref="T:OpenQA.Selenium.By" /> object containing the method used to find elements.</param>
 public FoundElementEventArgs(IWebDriver driver, IWebElement element, OpenQA.Selenium.By method)
 {
     Driver     = driver;
     Element    = element;
     FindMethod = method;
 }
Exemplo n.º 41
0
 public AssertionResultPage InputFixtureA()
 {
     Input().Model(Form1Fixtures.A);
     return(Navigate().To <AssertionResultPage>(By.CssSelector("input[type=submit]")));
 }
Exemplo n.º 42
0
 public TResult ActionOnLocator <TResult>(By findExpression, Func <IWebElement, TResult> func, int maxWaitInSeconds = 5)
 {
     throw new NotImplementedException("Obsolete");
 }
Exemplo n.º 43
0
 /// <summary>
 /// Waits to find the first matching <see cref="IWidget"/> using the specified locator.
 /// </summary>
 /// <param name="by">The locating mechanism to use.</param>
 /// <param name="timeoutInSeconds">The number of seconds to wait for the widget.</param>
 /// <returns>The first matching element on the current page.</returns>
 /// <exception cref="NoSuchElementException"> If no matching widget was found before the timeout elapsed </exception>
 /// <seealso cref="By"/>
 public virtual IWidget WaitForWidget(OpenQA.Selenium.By by, int timeoutInSeconds)
 {
     return(FindWidget(by, timeoutInSeconds));
 }
Exemplo n.º 44
0
 /// <summary>
 /// Finds all <see cref="IWebElement"/> within the current context
 /// using the specified mechanism.
 /// </summary>
 /// <param name="by">The locating mechanism to use.</param>
 /// <returns>A <see cref="ReadOnlyCollection{IWebElement}"/> of all <see cref="IWebElement"/>
 /// matching the current criteria, or an empty list if nothing matches.</returns>
 public ReadOnlyCollection <IWebElement> FindElements(OpenQA.Selenium.By by)
 {
     return(_driver.FindElements(by));
 }
Exemplo n.º 45
0
 public IWebElement WithPatience(By findElement, Action <IWebElement> action, int waitInSeconds = 20)
 {
     throw new NotImplementedException("Obsolete");
 }
Exemplo n.º 46
0
        /// <summary>
        /// Finds a widget relative to the current one by traversing the qooxdoo
        /// widget hierarchy.
        /// </summary>
        /// <param name="by">The locating mechanism to use.</param>
        /// <param name="timeoutInSeconds">The number of seconds to wait for the widget.</param>
        /// <returns>The matching widget.</returns>
        public virtual IWidget WaitForWidget(OpenQA.Selenium.By by, long timeoutInSeconds)
        {
            IWebElement element = FindElement(by, timeoutInSeconds);

            return(Driver.GetWidgetForElement(element));
        }
Exemplo n.º 47
0
 /// <summary>
 /// Finds the first <see cref="IWebElement" /> using the specified method.
 /// </summary>
 /// <param name="by">The locating mechanism to use.</param>
 /// <returns>The first matching <see cref="IWebElement" /> on the current context.</returns>
 /// <exception cref="NoSuchElementException">If no element matches the criteria.</exception>
 public IWebElement FindElement(OpenQA.Selenium.By by)
 {
     return(_driver.FindElement(by));
 }
Exemplo n.º 48
0
 public IWebElement Element(By findExpression, TimeSpan maxWait = default(TimeSpan))
 {
     return(Browser.ElementWithWait(d => d.FindElement(findExpression), maxWait));
 }
 public static IList <Fieldset> Fieldsets(this ISearchContext context, OpenQA.Selenium.By constraint = null)
 {
     return(context.Find <Fieldset>(constraint));
 }
 public static IList <Section> Sections(this ISearchContext context, OpenQA.Selenium.By constraint = null)
 {
     return(context.Find <Section>(constraint));
 }
 public static IList <Article> Articles(this ISearchContext context, OpenQA.Selenium.By constraint = null)
 {
     return(context.Find <Article>(constraint));
 }
Exemplo n.º 52
0
        private IWebElement FindElement(OpenQA.Selenium.By by, long timeoutInSeconds)
        {
            WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(timeoutInSeconds));

            return(wait.Until(IsRendered(_contentElement, by)));
        }
 public static H1 H1(this ISearchContext context, OpenQA.Selenium.By constraint)
 {
     return(context.Find <H1>(constraint).SingleOrThrowNotFoundException());
 }
Exemplo n.º 54
0
 public IWebElement FindElement(By @by)
 {
     throw new NotSupportedException();
 }
 /// <summary>
 /// Gets a mechanism to find elements by their tag name.
 /// </summary>
 /// <param name="tagNameToFind">The tag name to find.</param>
 /// <returns>A <see cref="OpenQA.Selenium.By"/> object the driver can use to find the elements.</returns>
 public static new SeleniumBy TagName(string tagNameToFind) => SeleniumBy.TagName(tagNameToFind);
Exemplo n.º 56
0
 /// <summary>
 /// A condition that checks if an element is rendered.
 /// </summary>
 /// <param name="element">The element.</param>
 /// <param name="by">The locating mechanism to use.</param>
 /// <returns>.</returns>
 public Func <IWebDriver, IWebElement> IsRendered(IWebElement element, OpenQA.Selenium.By by)
 {
     return((driver) => { return element.FindElement(by); });
 }
Exemplo n.º 57
0
 public IWebElement ElementWithWait(By findElement, int waitInSeconds = 20)
 {
     throw new NotImplementedException("Obsolete");
 }
 /// <summary>
 /// Gets a mechanism to find elements by an XPath query. When searching within a <see cref="IWebElement"/>
 /// using xpath be aware that <see cref="IWebDriver"/> follows standard conventions: a search prefixed with
 /// <c>"//"</c> will search the entire document, not just the children of this current node. Use <c>".//"</c>
 /// to limit your search to the children of this <see cref="IWebElement"/>.
 /// </summary>
 /// <param name="xpathToFind">The XPath query to use.</param>
 /// <returns>A <see cref="OpenQA.Selenium.By"/> object the driver can use to find the elements.</returns>
 public static new SeleniumBy XPath(string xpathToFind) => SeleniumBy.XPath(xpathToFind);
Exemplo n.º 59
0
 public IWebElement TryFindElement(By @by)
 {
     throw new NotImplementedException("Obsolete");
 }
 /// <summary>
 /// Gets a mechanism to find elements by a partial match on their link text.
 /// </summary>
 /// <param name="partialLinkTextToFind">The partial link text to find.</param>
 /// <returns>A <see cref="OpenQA.Selenium.By"/> object the driver can use to find the elements.</returns>
 public static new SeleniumBy PartialLinkText(string partialLinkTextToFind) =>
 SeleniumBy.PartialLinkText(partialLinkTextToFind);