예제 #1
0
        public void SwitchToFrame(string frameNameOrSelector)
        {
            this.Act(CommandType.Action, () =>
            {
                if (frameNameOrSelector == string.Empty)
                {
                    this._webDriver.SwitchTo().DefaultContent();
                    return;
                }

                // try to locate frame using argument as a selector, if that fails pass it into Frame so it can be
                // evaluated as a name by Selenium
                IWebElement frameBySelector = null;
                try
                {
                    frameBySelector = this._webDriver.FindElement(Sizzle.Find(frameNameOrSelector));
                }
                catch (NoSuchElementException)
                {
                }

                if (frameBySelector == null)
                {
                    this._webDriver.SwitchTo().Frame(frameNameOrSelector);
                }
                else
                {
                    this._webDriver.SwitchTo().Frame(frameBySelector);
                }
            });
        }
예제 #2
0
 public ElementProxy Find(string selector)
 {
     return(new ElementProxy(this, () =>
     {
         try
         {
             var webElement = this._webDriver.FindElement(Sizzle.Find(selector));
             return new Element(webElement, selector);
         }
         catch (NoSuchElementException)
         {
             throw new FluentElementNotFoundException("Unable to find element with selector [{0}]", selector);
         }
     }));
 }
 public Func <IElement> Find(string selector)
 {
     return(new Func <IElement>(() =>
     {
         try
         {
             var webElement = this.webDriver.FindElement(Sizzle.Find(selector));
             return new Element(webElement, selector);
         }
         catch (NoSuchElementException)
         {
             throw new FluentException("Unable to find element with selector [{0}]", selector);
         }
     }));
 }
 public Func <IEnumerable <IElement> > FindMultiple(string selector)
 {
     return(new Func <IEnumerable <IElement> >(() =>
     {
         try
         {
             var webElements = this.webDriver.FindElements(Sizzle.Find(selector));
             List <Element> resultSet = new List <Element>();
             webElements.ToList().ForEach(x => resultSet.Add(new Element(x, selector)));
             return resultSet;
         }
         catch (NoSuchElementException)
         {
             throw new FluentException("Unable to find element with selector [{0}]", selector);
         }
     }));
 }
예제 #5
0
        public ElementProxy FindMultiple(string selector)
        {
            var finalResult = new ElementProxy();

            finalResult.Children.Add(new Func <ElementProxy>(() =>
            {
                var result      = new ElementProxy();
                var webElements = this._webDriver.FindElements(Sizzle.Find(selector));
                if (webElements.Count == 0)
                {
                    throw new FluentElementNotFoundException("Unable to find element with selector [{0}].", selector);
                }

                foreach (var element in webElements)
                {
                    result.Elements.Add(new Tuple <ICommandProvider, Func <IElement> >(this, () => new Element(element, selector)));
                }

                return(result);
            }));

            return(finalResult);
        }