//设置主自动化对象的快捷方式。浏览器= mgr.ActiveBrowser;查找rootFind = browser .Find;//所有的testregion都在这里初始化。testregionr1 = browser . regions ["Region1"];TestRegion r11 = browser . regions ["Region11"];TestRegion r111 = browser . regions ["Region111"];TestRegion r1111 = browser . regions ["Region1111"];TestRegion r112 = browser . regions ["Region112"];//***使用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.IsTrue(rootFind.ByAttributes("id=bla") == null); 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.IsTrue(rootFind.AllByTagName("div").Count - 1 == rootFind.AllByXPath("/descendant::node()[starts-with(@id,'div')]").Count); Assert.IsTrue(rootFind.AllByAttributes("href=http://www.kayak.com").Count == 5); Assert.IsTrue(rootFind.AllByAttributes("id=~button").Count == 2); Assert.IsTrue(r1.Find.AllByTagName("div").Count == 10); Assert.IsTrue(r1111.Find.AllByTagName("div").Count == 0); Assert.IsTrue(r111.Find.AllByTagName("a").Count == 2); Assert.IsTrue(r11.Find.AllByAttributes("id=~div").Count == 9); //*** 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"));
将快捷方式设置为主要自动化对象。Dim浏览器作为ArtOfTest.WebAii.Core.Browser = Manager。ActiveBrowser Dim rootFind As Find = browser。找到' All the testregion are initialized here. Dim r1 As TestRegion = brwser.Regions("Region1") Dim r11 As TestRegion = brwser.Regions("Region11") Dim r111 As TestRegion = brwser.Regions("Region111") Dim r1111 As TestRegion = brwser.Regions("Region1111") Dim r112 As TestRegion = brwser.Regions("Region112") '*** Using identification by id. Dim div0 As Element = r1.Find.ById("div0") '*** Using tag name occurrence index. Dim div As Element = r1.Find.ByTagIndex("div", 0) Dim div1 As Element = r112.Find.ByTagIndex("div", 0) ' Some verification to illustrate how the same element that was found ' Imports TestRegion Find objects above, can be also found ' Imports 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"))