public void FindAllByxx()
        {
            //
            // The Find.AllByxx methods allow you to find multiple elements on the page using certain criteria
            //

            // Example 1: Get all table elements on the page.
            //
            IList <Element> tables = Find.AllByTagName("table");

            Assert.IsTrue(tables.Count == 2);

            // Example 2: Get all table cells that contain a 'yes'
            //
            IList <Element> cells = Find.AllByContent("yes");

            Assert.IsTrue(cells.Count == 5);

            // Example 3: Find all table rows that contain a scope=row attribute
            IList <Element> rows = Find.AllByAttributes("scope=row"); // partial compare (~) is also supported

            Assert.IsTrue(rows.Count == 3);

            // Example 4: Same as #1 above but using an XPath
            tables = Find.AllByXPath("/descendant::table");
            Assert.IsTrue(tables.Count == 2);
        }
Exemple #2
0
        public void FindElementsByID()
        {
            Manager.LaunchNewBrowser();
            ActiveBrowser.NavigateTo(Path.Combine(TestContext.TestDeploymentDir, TESTPAGE));

            // Set the short-cuts to the main automation objects.
            Browser brwser   = Manager.ActiveBrowser;
            Find    rootFind = brwser.Find;

            // All the testregion are initialized here.
            TestRegion r1    = brwser.Regions["Region1"];
            TestRegion r11   = brwser.Regions["Region11"];
            TestRegion r111  = brwser.Regions["Region111"];
            TestRegion r1111 = brwser.Regions["Region1111"];
            TestRegion r112  = brwser.Regions["Region112"];

            //*** Using identification by id.
            Element div0 = r1.Find.ById("div0");

            //*** Using tag name occurrence index.
            Element div  = r1.Find.ByTagIndex("div", 0);
            Element div1 = r112.Find.ByTagIndex("div", 0);

            // Some verification to illustrate how the same element that was found
            // using TestRegion Find objects above, can be also found
            // using the main Browser Find object.
            Assert.IsTrue(div.Equals(rootFind.ByTagIndex("div", 0)));
            Assert.IsTrue(div0.Equals(rootFind.ByTagIndex("div", 1)));

            //*** Using attribute identification.
            Assert.IsTrue(div1.Equals(rootFind.ByAttributes("id=div1")));
            Assert.IsNull(rootFind.ByAttributes("id=bla"));
            Assert.IsNotNull(rootFind.ByAttributes("href=http://www.kayak.com"));

            //*** Using partial attribute identification.
            Assert.IsTrue(rootFind.ByAttributes("bla=~__").Equals(rootFind.ById("div7")));
            Assert.IsNull(rootFind.ByAttributes("id=~div7", "bla=~wow"));
            Assert.IsNotNull(rootFind.ByAttributes("onclick=~clicked();", "id=~button2"));

            //*** Using 'All' elements identification.

            // Note here that the first 'div' does not have any id that contains 'div' hence the '- 1'.
            Assert.AreEqual(rootFind.AllByTagName("div").Count - 1,
                            rootFind.AllByXPath("/descendant::node()[starts-with(@id,'div')]").Count);

            Assert.AreEqual(5, rootFind.AllByAttributes("href=http://www.kayak.com").Count);
            Assert.AreEqual(2, rootFind.AllByAttributes("id=~button").Count);
            Assert.AreEqual(10, r1.Find.AllByTagName("div").Count);
            Assert.AreEqual(0, r1111.Find.AllByTagName("div").Count);
            Assert.AreEqual(2, r111.Find.AllByTagName("a").Count);
            Assert.AreEqual(9, r11.Find.AllByAttributes("id=~div").Count);

            //*** Using NodeIndexPath identification.
            Assert.IsTrue(r1.Find.ByNodeIndexPath("0/1/1").IdAttributeValue.Equals("input1"));
            Assert.IsTrue(rootFind.ByNodeIndexPath("1/0/0").TagName.Equals("div", StringComparison.OrdinalIgnoreCase));

            //*** Using name
            Assert.IsNull(r1.Find.ByName("bla"));
        }