Пример #1
0
        /// <summary>
        /// Returns a web element matching the given method and value
        /// </summary>
        private void WaitAnyElementNotPresent(By byAny, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/element";
            DateTime      endTime = session.GetEndTime(timeout);

            foreach (By by in (By[])byAny.Value)
            {
                if (by == null)
                {
                    break;
                }
                try {
                    string method = By.FormatStrategy(by.Strategy);
                    string value  = by.Value.ToString();
                    session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                    while (true)
                    {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw new Errors.ElementPresentError(byAny);
                        }
                        SysWaiter.Wait();
                        session.SendAgain();
                    }
                } catch (Errors.NoSuchElementError) { }
            }
        }
Пример #2
0
        private WebElements FindAnyElements(By byAny, int minimum, int timeout)
        {
            RemoteSession session     = this.session;
            string        uri         = this.uri + "/elements";
            WebElements   webelements = new WebElements();
            DateTime      endTime     = session.GetEndTime(timeout);

            while (true)
            {
                foreach (By by in (By[])byAny.Value)
                {
                    if (by == null)
                    {
                        break;
                    }
                    var  method   = By.FormatStrategy(by.Strategy);
                    var  value    = (string)by.Value;
                    List elements = (List)session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                    webelements.Add(session, elements);
                }
                if (webelements.Count >= minimum)
                {
                    return(webelements);
                }
                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchElementError(byAny);
                }
                SysWaiter.Wait();
            }
        }
Пример #3
0
        private WebElement FindAnyElement(By byAny, int timeout)
        {
            RemoteSession session     = this.session;
            string        relativeUri = this.uri + "/element";
            Dictionary    element;
            DateTime      endTime = session.GetEndTime(timeout);

            while (true)
            {
                foreach (By by in (By[])byAny.Value)
                {
                    if (by == null)
                    {
                        break;
                    }
                    try {
                        string method = By.FormatStrategy(by.Strategy);
                        string value  = by.Value.ToString();
                        element = (Dictionary)session.Send(RequestMethod.POST, relativeUri, "using", method, "value", value);
                        return(new WebElement(session, element));
                    } catch (Errors.NoSuchElementError) { }
                }
                if (DateTime.UtcNow > endTime)
                {
                    throw new Errors.NoSuchElementError(byAny);
                }
                SysWaiter.Wait();
            }
        }
Пример #4
0
        /// <summary>
        /// Returns a web element matching the given method and value or null if no element found
        /// </summary>
        private WebElement FindFirstElement(Strategy strategy, string value, int timeout)
        {
            RemoteSession session     = this.session;
            string        relativeUri = this.uri + "/element";
            Dictionary    element;

            try {
                string method = By.FormatStrategy(strategy);
                element = (Dictionary)session.Send(RequestMethod.POST, relativeUri, "using", method, "value", value);
            } catch (Errors.NoSuchElementError) {
                if (timeout == 0)
                {
                    throw;
                }
                var endTime = session.GetEndTime(timeout);
                while (true)
                {
                    SysWaiter.Wait();
                    try {
                        element = (Dictionary)session.SendAgain();
                        break;
                    } catch (Errors.NoSuchElementError) {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw;
                        }
                    }
                }
            }
            return(new WebElement(session, element));
        }
Пример #5
0
        /// <summary>
        /// Returns all the web elements matching the given method and value
        /// </summary>
        private WebElements FindAllElements(Strategy strategy, string value, int minimum, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/elements";

            try {
                var  method   = By.FormatStrategy(strategy);
                List elements = session.SendUntil(timeout,
                                                  () => (List)session.Send(RequestMethod.POST, uri, "using", method, "value", value),
                                                  (r) => r.Count >= minimum
                                                  );
                return(new WebElements(session, elements));
            } catch (Errors.TimeoutError) {
                throw new Errors.NoSuchElementError(strategy, value);
            }
        }
Пример #6
0
        /// <summary>
        /// Returns a web element matching the given method and value
        /// </summary>
        private void WaitElementNotPresent(Strategy strategy, string value, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/element";
            string        method  = By.FormatStrategy(strategy);
            DateTime      endTime = session.GetEndTime(timeout);

            try {
                session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                while (true)
                {
                    SysWaiter.Wait();
                    session.SendAgain();
                    if (DateTime.UtcNow > endTime)
                    {
                        throw new Errors.ElementPresentError(strategy, value);
                    }
                }
            } catch (Errors.NoSuchElementError) { }
        }