FindElement() 공개 메소드

Find the first IWebElement using the given method.
If no element matches the criteria.
public FindElement ( By by ) : IWebElement
by By The locating mechanism to use.
리턴 IWebElement
예제 #1
0
        public void ElementsCanEqual()
        {
            mockDriver.Setup(_ => _.FindElement(It.Is <By>(x => x.Equals(By.Id("foo"))))).Returns(mockElement.Object);

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object);
            var element1 = firingDriver.FindElement(By.Id("foo"));
            var element2 = firingDriver.FindElement(By.Id("foo"));

            Assert.AreEqual(element1, element2);
        }
예제 #2
0
        public void ShouldFireFindByEvent()
        {
            IList <IWebElement> driverElements = new List <IWebElement>();
            IList <IWebElement> subElements    = new List <IWebElement>();
            Mock <IWebElement>  ignored        = new Mock <IWebElement>();

            mockDriver.Setup(_ => _.FindElement(It.Is <By>(x => x.Equals(By.Id("foo"))))).Returns(mockElement.Object);
            mockElement.Setup(_ => _.FindElement(It.IsAny <By>())).Returns(ignored.Object);
            mockElement.Setup(_ => _.FindElements(It.Is <By>(x => x.Equals(By.Name("xyz"))))).Returns(new ReadOnlyCollection <IWebElement>(driverElements));
            mockDriver.Setup(_ => _.FindElements(It.Is <By>(x => x.Equals(By.XPath("//link[@type = 'text/css']"))))).Returns(new ReadOnlyCollection <IWebElement>(subElements));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object);

            firingDriver.FindingElement       += new EventHandler <FindElementEventArgs>(firingDriver_FindingElement);
            firingDriver.FindElementCompleted += new EventHandler <FindElementEventArgs>(firingDriver_FindElementCompleted);

            IWebElement element = firingDriver.FindElement(By.Id("foo"));

            element.FindElement(By.LinkText("bar"));
            element.FindElements(By.Name("xyz"));
            firingDriver.FindElements(By.XPath("//link[@type = 'text/css']"));

            string expectedLog = @"FindingElement from IWebDriver By.Id: foo
FindElementCompleted from IWebDriver By.Id: foo
FindingElement from IWebElement By.LinkText: bar
FindElementCompleted from IWebElement By.LinkText: bar
FindingElement from IWebElement By.Name: xyz
FindElementCompleted from IWebElement By.Name: xyz
FindingElement from IWebDriver By.XPath: //link[@type = 'text/css']
FindElementCompleted from IWebDriver By.XPath: //link[@type = 'text/css']
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
        public void ShouldFireFindByEvent()
        {
            IList <IWebElement> driverElements = new List <IWebElement>();
            IList <IWebElement> subElements    = new List <IWebElement>();

            Expect.Once.On(mockDriver).Method("FindElement").With(By.Id("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(mockElement).Method("FindElement").With(By.LinkText("bar"));
            Expect.Once.On(mockElement).Method("FindElements").With(By.Name("xyz")).Will(Return.Value(new ReadOnlyCollection <IWebElement>(driverElements)));
            Expect.Once.On(mockDriver).Method("FindElements").With(By.XPath("//link[@type = 'text/css']")).Will(Return.Value(new ReadOnlyCollection <IWebElement>(subElements)));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);

            firingDriver.FindingElement       += new EventHandler <FindElementEventArgs>(firingDriver_FindingElement);
            firingDriver.FindElementCompleted += new EventHandler <FindElementEventArgs>(firingDriver_FindElementCompleted);

            IWebElement element = firingDriver.FindElement(By.Id("foo"));

            element.FindElement(By.LinkText("bar"));
            element.FindElements(By.Name("xyz"));
            firingDriver.FindElements(By.XPath("//link[@type = 'text/css']"));

            string expectedLog = @"FindingElement from IWebDriver By.Id: foo
FindElementCompleted from IWebDriver By.Id: foo
FindingElement from IWebElement By.LinkText: bar
FindElementCompleted from IWebElement By.LinkText: bar
FindingElement from IWebElement By.Name: xyz
FindElementCompleted from IWebElement By.Name: xyz
FindingElement from IWebDriver By.XPath: //link[@type = 'text/css']
FindElementCompleted from IWebDriver By.XPath: //link[@type = 'text/css']
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
예제 #4
0
        public void ShouldFireFindByEvent()
        {
            IList <IWebElement> driverElements = new List <IWebElement>();
            IList <IWebElement> subElements    = new List <IWebElement>();
            Mock <IWebElement>  ignored        = mocks.CreateMock <IWebElement>();

            mockDriver.Expects.One.Method(_ => _.FindElement(null)).With(By.Id("foo")).WillReturn(mockElement.MockObject);
            mockElement.Expects.One.Method(_ => _.FindElement(null)).WithAnyArguments().WillReturn(ignored.MockObject);
            mockElement.Expects.One.Method(_ => _.FindElements(null)).With(By.Name("xyz")).WillReturn(new ReadOnlyCollection <IWebElement>(driverElements));
            mockDriver.Expects.One.Method(_ => _.FindElements(null)).With(By.XPath("//link[@type = 'text/css']")).WillReturn(new ReadOnlyCollection <IWebElement>(subElements));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.MockObject);

            firingDriver.FindingElement       += new EventHandler <FindElementEventArgs>(firingDriver_FindingElement);
            firingDriver.FindElementCompleted += new EventHandler <FindElementEventArgs>(firingDriver_FindElementCompleted);

            IWebElement element = firingDriver.FindElement(By.Id("foo"));

            element.FindElement(By.LinkText("bar"));
            element.FindElements(By.Name("xyz"));
            firingDriver.FindElements(By.XPath("//link[@type = 'text/css']"));

            string expectedLog = @"FindingElement from IWebDriver By.Id: foo
FindElementCompleted from IWebDriver By.Id: foo
FindingElement from IWebElement By.LinkText: bar
FindElementCompleted from IWebElement By.LinkText: bar
FindingElement from IWebElement By.Name: xyz
FindElementCompleted from IWebElement By.Name: xyz
FindingElement from IWebDriver By.XPath: //link[@type = 'text/css']
FindElementCompleted from IWebDriver By.XPath: //link[@type = 'text/css']
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
예제 #5
0
        public void CanTakeEventFiringWebElementScreenshot()
        {
            var         firingDriver = new EventFiringWebDriver(driver);
            IWebElement element      = firingDriver.FindElement(By.Name("checky"));
            Screenshot  screenshot   = ((ITakesScreenshot)element).GetScreenshot();

            Assert.IsNotNull(screenshot);
        }
        public void ShouldFireClickEvent()
        {
            Expect.Once.On(mockDriver).Method("FindElement").With(By.Name("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(mockElement).Method("Click");

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);
            firingDriver.ElementClicking += new EventHandler<WebElementEventArgs>(firingDriver_ElementClicking);
            firingDriver.ElementClicked += new EventHandler<WebElementEventArgs>(firingDriver_ElementClicked);

            firingDriver.FindElement(By.Name("foo")).Click();

            string expectedLog = @"Clicking
Clicked
";
            Assert.AreEqual(expectedLog, log.ToString());
        }
        public void ShouldFireClickEvent()
        {
            Expect.Once.On(mockDriver).Method("FindElement").With(By.Name("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(mockElement).Method("Click");

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);

            firingDriver.ElementClicking += new EventHandler <WebElementEventArgs>(firingDriver_ElementClicking);
            firingDriver.ElementClicked  += new EventHandler <WebElementEventArgs>(firingDriver_ElementClicked);

            firingDriver.FindElement(By.Name("foo")).Click();

            string expectedLog = @"Clicking
Clicked
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
예제 #8
0
        public void ShouldFireClickEvent()
        {
            mockDriver.Expects.One.Method(_ => _.FindElement(null)).With(By.Name("foo")).WillReturn(mockElement.MockObject);
            mockElement.Expects.One.Method(_ => _.Click());

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.MockObject);

            firingDriver.ElementClicking += new EventHandler <WebElementEventArgs>(firingDriver_ElementClicking);
            firingDriver.ElementClicked  += new EventHandler <WebElementEventArgs>(firingDriver_ElementClicked);

            firingDriver.FindElement(By.Name("foo")).Click();

            string expectedLog = @"Clicking
Clicked
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
예제 #9
0
        public void ShouldFireClickEvent()
        {
            mockDriver.Setup(_ => _.FindElement(It.IsAny <By>())).Returns(mockElement.Object);
            mockElement.Setup(_ => _.Click());

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object);

            firingDriver.ElementClicking += new EventHandler <WebElementEventArgs>(firingDriver_ElementClicking);
            firingDriver.ElementClicked  += new EventHandler <WebElementEventArgs>(firingDriver_ElementClicked);

            firingDriver.FindElement(By.Name("foo")).Click();

            string expectedLog = @"Clicking
Clicked
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
        public void ShouldCallListenerOnException()
        {
            NoSuchElementException exception = new NoSuchElementException("argh");
            Expect.Once.On(mockDriver).Method("FindElement").With(By.Id("foo")).Will(Throw.Exception(exception));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);
            firingDriver.ExceptionThrown += new EventHandler<WebDriverExceptionEventArgs>(firingDriver_ExceptionThrown);

            try
            {
                firingDriver.FindElement(By.Id("foo"));
                Assert.Fail("Expected exception to be propogated");
            }
            catch (NoSuchElementException)
            {
                // Fine
            }

            Assert.AreEqual(exception.Message, log.ToString());
        }
        public void ShouldUnwrapElementArgsWhenCallingScripts()
        {
            IExecutingDriver executingDriver = mocks.NewMock <IExecutingDriver>();

            Expect.Once.On(executingDriver).Method("FindElement").With(By.Id("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(executingDriver).Method("ExecuteScript").With("foo", new[] { mockElement }).Will(Return.Value("foo"));

            EventFiringWebDriver testedDriver = new EventFiringWebDriver(executingDriver);

            IWebElement element = testedDriver.FindElement(By.Id("foo"));

            try
            {
                testedDriver.ExecuteScript("foo", element);
            }
            catch (Exception e)
            {
                // This is the error we're trying to fix
                throw e;
            }
        }
예제 #12
0
        public void ShouldUnwrapElementArgsWhenCallingScripts()
        {
            Mock <IExecutingDriver> executingDriver = new Mock <IExecutingDriver>();

            executingDriver.Setup(_ => _.FindElement(It.Is <By>(x => x.Equals(By.Id("foo"))))).Returns(mockElement.Object);
            executingDriver.Setup(_ => _.ExecuteScript(It.IsAny <string>(), It.IsAny <object[]>())).Returns("foo");

            EventFiringWebDriver testedDriver = new EventFiringWebDriver(executingDriver.Object);

            IWebElement element = testedDriver.FindElement(By.Id("foo"));

            try
            {
                testedDriver.ExecuteScript("foo", element);
            }
            catch (Exception e)
            {
                // This is the error we're trying to fix
                throw e;
            }
        }
예제 #13
0
        public void ShouldUnwrapElementArgsWhenCallingScripts()
        {
            Mock <IExecutingDriver> executingDriver = mocks.CreateMock <IExecutingDriver>();

            executingDriver.Expects.One.Method(_ => _.FindElement(null)).With(By.Id("foo")).WillReturn(mockElement.MockObject);
            executingDriver.Expects.One.Method(_ => _.ExecuteScript(null, null)).With("foo", new[] { mockElement.MockObject }).WillReturn("foo");

            EventFiringWebDriver testedDriver = new EventFiringWebDriver(executingDriver.MockObject);

            IWebElement element = testedDriver.FindElement(By.Id("foo"));

            try
            {
                testedDriver.ExecuteScript("foo", element);
            }
            catch (Exception e)
            {
                // This is the error we're trying to fix
                throw e;
            }
        }
예제 #14
0
        public void ShouldCallListenerOnException()
        {
            NoSuchElementException exception = new NoSuchElementException("argh");

            mockDriver.Expects.One.Method(_ => _.FindElement(null)).With(By.Id("foo")).Will(Throw.Exception(exception));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.MockObject);

            firingDriver.ExceptionThrown += new EventHandler <WebDriverExceptionEventArgs>(firingDriver_ExceptionThrown);

            try
            {
                firingDriver.FindElement(By.Id("foo"));
                Assert.Fail("Expected exception to be propogated");
            }
            catch (NoSuchElementException)
            {
                // Fine
            }

            Assert.IsTrue(log.ToString().Contains(exception.Message));
        }
예제 #15
0
        public void ShouldCallListenerOnException()
        {
            NoSuchElementException exception = new NoSuchElementException("argh");

            mockDriver.Setup(_ => _.FindElement(It.Is <By>(x => x.Equals(By.Id("foo"))))).Throws(exception);

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object);

            firingDriver.ExceptionThrown += new EventHandler <WebDriverExceptionEventArgs>(firingDriver_ExceptionThrown);

            try
            {
                firingDriver.FindElement(By.Id("foo"));
                Assert.Fail("Expected exception to be propogated");
            }
            catch (NoSuchElementException)
            {
                // Fine
            }

            Assert.IsTrue(log.ToString().Contains(exception.Message));
        }
예제 #16
0
        public void ShouldCallListenerOnException()
        {
            NoSuchElementException exception = new NoSuchElementException("argh");

            Expect.Once.On(mockDriver).Method("FindElement").With(By.Id("foo")).Will(Throw.Exception(exception));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);

            firingDriver.ExceptionThrown += new EventHandler <WebDriverExceptionEventArgs>(firingDriver_ExceptionThrown);

            try
            {
                firingDriver.FindElement(By.Id("foo"));
                Assert.Fail("Expected exception to be propogated");
            }
            catch (NoSuchElementException)
            {
                // Fine
            }

            Assert.AreEqual(exception.Message, log.ToString());
        }
예제 #17
0
        public void ShouldFireValueChangedEvent()
        {
            mockDriver.Setup(_ => _.FindElement(It.IsAny <By>())).Returns(mockElement.Object);
            mockElement.Setup(_ => _.Clear());
            mockElement.Setup(_ => _.SendKeys(It.IsAny <string>()));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver.Object);

            firingDriver.ElementValueChanging += (sender, e) => log.AppendFormat("ValueChanging '{0}'", e.Value).AppendLine();
            firingDriver.ElementValueChanged  += (sender, e) => log.AppendFormat("ValueChanged '{0}'", e.Value).AppendLine();

            var element = firingDriver.FindElement(By.Name("foo"));

            element.Clear();
            element.SendKeys("Dummy Text");

            string expectedLog = @"ValueChanging ''
ValueChanged ''
ValueChanging 'Dummy Text'
ValueChanged 'Dummy Text'
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
        public void ShouldFireFindByEvent()
        {
            IList<IWebElement> driverElements = new List<IWebElement>();
            IList<IWebElement> subElements = new List<IWebElement>();
            Expect.Once.On(mockDriver).Method("FindElement").With(By.Id("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(mockElement).Method("FindElement").With(By.LinkText("bar"));
            Expect.Once.On(mockElement).Method("FindElements").With(By.Name("xyz")).Will(Return.Value(new ReadOnlyCollection<IWebElement>(driverElements)));
            Expect.Once.On(mockDriver).Method("FindElements").With(By.XPath("//link[@type = 'text/css']")).Will(Return.Value(new ReadOnlyCollection<IWebElement>(subElements)));

            EventFiringWebDriver firingDriver = new EventFiringWebDriver(mockDriver);
            firingDriver.FindingElement += new EventHandler<FindElementEventArgs>(firingDriver_FindingElement);
            firingDriver.FindElementCompleted += new EventHandler<FindElementEventArgs>(firingDriver_FindElementCompleted);

            IWebElement element = firingDriver.FindElement(By.Id("foo"));
            element.FindElement(By.LinkText("bar"));
            element.FindElements(By.Name("xyz"));
            firingDriver.FindElements(By.XPath("//link[@type = 'text/css']"));

            string expectedLog = @"FindingElement from IWebDriver By.Id: foo
FindElementCompleted from IWebDriver By.Id: foo
FindingElement from IWebElement By.LinkText: bar
FindElementCompleted from IWebElement By.LinkText: bar
FindingElement from IWebElement By.Name: xyz
FindElementCompleted from IWebElement By.Name: xyz
FindingElement from IWebDriver By.XPath: //link[@type = 'text/css']
FindElementCompleted from IWebDriver By.XPath: //link[@type = 'text/css']
";

            Assert.AreEqual(expectedLog, log.ToString());
        }
        public void ShouldUnwrapElementArgsWhenCallingScripts()
        {
            IExecutingDriver executingDriver = mocks.NewMock<IExecutingDriver>();
            Expect.Once.On(executingDriver).Method("FindElement").With(By.Id("foo")).Will(Return.Value(mockElement));
            Expect.Once.On(executingDriver).Method("ExecuteScript").With("foo", new[] { mockElement }).Will(Return.Value("foo"));

            EventFiringWebDriver testedDriver = new EventFiringWebDriver(executingDriver);

            IWebElement element = testedDriver.FindElement(By.Id("foo"));
            try
            {
                testedDriver.ExecuteScript("foo", element);
            }
            catch (Exception e)
            {
                // This is the error we're trying to fix
                throw e;
            }
        }