FindElement() 공개 메소드

Finds the first element matching the criteria.
public FindElement ( ISearchContext context ) : IWebElement
context ISearchContext An object to use to search for the elements.
리턴 IWebElement
예제 #1
0
        /// <summary>
        /// Finds the first element in the page that matches the <see cref="By"/> object
        /// </summary>
        /// <param name="by">By mechanism to find the object</param>
        /// <returns>IWebElement object so that you can interact with that object</returns>
        /// <example>
        /// <code>
        /// IWebDriver driver = new InternetExplorerDriver();
        /// IWebElement elem = driver.FindElement(By.Name("q"));
        /// </code>
        /// </example>
        public IWebElement FindElement(By by)
        {
            if (by == null)
            {
                throw new ArgumentNullException("by", "by cannot be null");
            }

            return(by.FindElement(this));
        }
예제 #2
0
        /// <summary>
        /// Finds the first <see cref="IWebElement"/> using the given 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 virtual IWebElement FindElement(By by)
        {
            if (by == null)
            {
                throw new ArgumentNullException(nameof(@by), "by cannot be null");
            }

            return(by.FindElement(this));
        }
예제 #3
0
        // TODO (jimevan): This test is disabled in the Java implementation unit tests.
        // Is the functionality not implemented?
        public void ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
        {
            DynamicMock driver = new DynamicMock(typeof(IOnlyXPath));

            driver.Expect("FindElementByXPath", new object[] { "//*[@name='cheese']" });

            By by = By.Name("cheese");

            by.FindElement(driver.MockInstance as IOnlyXPath);
        }
예제 #4
0
        public void ShouldUseFindsByNameToLocateElementsByName()
        {
            DynamicMock driver = new DynamicMock(typeof(IAllDriver));

            driver.Expect("FindElementByName", new object[] { "cheese" });

            By by = By.Name("cheese");

            by.FindElement(driver.MockInstance as IAllDriver);
        }
예제 #5
0
        // TODO (jimevan): This test is disabled in the Java implementation unit tests.
        // Is the functionality not implemented?
        public void ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
        {
            var mockDriver  = mocks.NewMock <IOnlyXPath>();
            var mockElement = mocks.NewMock <IWebElement>();

            Expect.Once.On(mockDriver).Method("FindElementByXPath").With("//*[@name='cheese']").Will(Return.Value(mockElement));

            By by = By.Name("cheese");

            by.FindElement(mockDriver);
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #6
0
        public void ShouldUseFindsByNameToLocateElementsByName()
        {
            var mockDriver  = mocks.NewMock <IAllDriver>();
            var mockElement = mocks.NewMock <IWebElement>();

            Expect.Once.On(mockDriver).Method("FindElementByName").With("cheese").Will(Return.Value(mockElement));

            By by = By.Name("cheese");

            by.FindElement(mockDriver);
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #7
0
        // TODO (jimevan): This test is disabled in the Java implementation unit tests.
        // Is the functionality not implemented?*
        public void ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
        {
            var mockDriver  = new Mock <IOnlyXPath>();
            var mockElement = new Mock <IWebElement>();

            mockDriver.Setup(_ => _.FindElementByXPath(It.Is <string>(x => x == "//*[@name='cheese']"))).Returns(mockElement.Object);

            By  by      = By.Name("cheese");
            var element = by.FindElement(mockDriver.Object);

            Assert.AreEqual(mockElement.Object, element);
        }
예제 #8
0
        // TODO (jimevan): This test is disabled in the Java implementation unit tests.
        // Is the functionality not implemented?*
        public void ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
        {
            var mockDriver  = mocks.CreateMock <IOnlyXPath>();
            var mockElement = mocks.CreateMock <IWebElement>();

            mockDriver.Expects.One.Method(_ => _.FindElementByXPath("//*[@name='cheese']")).WillReturn(mockElement.MockObject);

            By by = By.Name("cheese");

            by.FindElement(mockDriver.MockObject);
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #9
0
        public void ShouldUseFindsByNameToLocateElementsByName()
        {
            var mockDriver  = mocks.CreateMock <IAllDriver>();
            var mockElement = mocks.CreateMock <IWebElement>();

            mockDriver.Expects.One.Method(_ => _.FindElementByName(null)).With("cheese").Will(Return.Value(mockElement.MockObject));

            By by = By.Name("cheese");

            by.FindElement(mockDriver.MockObject);
            mocks.VerifyAllExpectationsHaveBeenMet();
        }
예제 #10
0
        public void ShouldUseFindsByNameToLocateElementsByName()
        {
            var mockDriver  = new Mock <IAllDriver>();
            var mockElement = new Mock <IWebElement>();

            mockDriver.Setup(_ => _.FindElementByName(It.Is <string>(x => x == "cheese"))).Returns(mockElement.Object);

            By  by      = By.Name("cheese");
            var element = by.FindElement(mockDriver.Object);

            Assert.AreEqual(mockElement.Object, element);
            mockDriver.Verify(x => x.FindElementByName("cheese"), Times.Once);
        }
예제 #11
0
 public IWebElement FindElement(By by)
 {
     return by.FindElement(this);
 }
예제 #12
0
        /// <summary>
        /// Verifica se o elemento não está presente na página.
        /// </summary>
        /// <param name="by">O seletor do elemento.</param>
        /// <returns>True se está presente, false no contrário.</returns>
        public static void AssertIsElementNotPresent(By by)
        {
            StepHelper.Attempt(() =>
            {
                return !IsElementPresent(by);
            });

            ExceptionAssert.IsThrowing(typeof(NoSuchElementException), () =>
            {
                by.FindElement(Driver);
            });
        }
예제 #13
0
 public IWebElement FindElement(By by)
 {
     return by.FindElement(new WebElementFinder(_browser.Page.HtmlNode(), Navigate()));
 }
예제 #14
0
 public IWebElement FindElement(By mechanism)
 {
     return mechanism.FindElement(new ElementFinderContext(_xElement));
 }
예제 #15
0
 public IWebElement FindElement(By mechanism)
 {
     return mechanism.FindElement(new ElementFinderContext(currentNode, webBrowser));
 }
 public IWebElement FindElement(By by)
 {
     ISearchContext ctx = CreateSearchContext(_my);
     return by.FindElement(ctx);
 }
예제 #17
0
        /// <summary>
        /// Verifica se o elemento está presente na página.
        /// </summary>
        /// <param name="by">O seletor do elemento.</param>
        /// <returns>True se está presente, false no contrário.</returns>
        public static void AssertIsElementPresent(By by)
        {
            StepHelper.Attempt(() =>
            {
                return IsElementPresent(by);
            });

            Assert.IsNotNull(by.FindElement(Driver));
        }