当前位置: 首页>>代码示例>>C#>>正文


C# Browser.Find方法代码示例

本文整理汇总了C#中Browser.Find方法的典型用法代码示例。如果您正苦于以下问题:C# Browser.Find方法的具体用法?C# Browser.Find怎么用?C# Browser.Find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Browser的用法示例。


在下文中一共展示了Browser.Find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Holding_Ctrl_Shft_Opens_New_Window

		public void Holding_Ctrl_Shft_Opens_New_Window()
		{
			Browser b = new Browser(Helper.GetMoviesRequestMocker());
			HttpRequestLog lastRequest = null;
			b.RequestLogged += (br, l) =>
			{
				lastRequest = l;
			};
			b.Navigate("http://localhost/movies/");
			Assert.That(b.Url == new Uri("http://localhost/movies/"));
			var link = b.Find(ElementType.Anchor, FindBy.Text, "Home");
			link.Click();
			Assert.That(b.Windows.Count() == 1);
			link = b.Find(ElementType.Anchor, FindBy.Text, "Home");
			b.KeyState = KeyStateOption.Ctrl;
			link.Click();
			Assert.That(b.Windows.Count() == 2);
			link = b.Find(ElementType.Anchor, FindBy.Text, "Home");
			b.KeyState = KeyStateOption.Shift;
			link.Click();
			Assert.That(b.Windows.Count() == 3);
			link = b.Find(ElementType.Anchor, FindBy.Text, "Home");
			b.KeyState = KeyStateOption.Alt;
			link.Click();
			Assert.That(b.Windows.Count() == 3); // alt does not open new browser
		}
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:26,代码来源:WindowsAndFrames.cs

示例2: HtmlElement_Comment

        public void HtmlElement_Comment()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.CommentElements.htm"));
            b.Find("link1");

            var comments = from node in b.XDocument.Elements().DescendantNodesAndSelf()
                           where node.NodeType == XmlNodeType.Comment
                           select node as XComment;

            var comment = comments.First();
            Assert.That(comment.ToString(), Is.EqualTo("<!-- Valid comment -->"));

            comment = comments.Skip(1).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!-- Malformed comment -->"));

              // Nr 3 is a comment inside a script block

            comment = comments.Skip(3).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!--[if gt IE 9]-->"));

            comment = comments.Skip(4).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!--[endif]-->"));

            comment = comments.Skip(5).First();
            Assert.That(comment.ToString(), Is.EqualTo("<!--[if gt IE 10]>\r\n<a id=\"link2\" href=\"http://www.microsoft.com\">Downlevel-hidden conditional comment test</a>\r\n<![endif]-->"));
        }
开发者ID:Buildstarted,项目名称:SimpleBrowser,代码行数:27,代码来源:CommentElements.cs

示例3: When_Testing_Referer_AlwaysMode_Secure_Transition

        public void When_Testing_Referer_AlwaysMode_Secure_Transition()
        {
            string startingUrl = "https://www.example.com/";

            Browser b = new Browser();
            b.RefererMode = Browser.RefererModes.Always;
            Assert.AreEqual(b.RefererMode, Browser.RefererModes.Always);

            b.Navigate(startingUrl);
            Assert.IsNotNull(b.CurrentState);
            Assert.IsNull(b.Referer);

            var link = b.Find(ElementType.Anchor, FindBy.Text, "More information...");
            Assert.IsNotNull(link);

            string targetHref = link.GetAttribute("href");
            Assert.AreEqual(targetHref, "http://www.iana.org/domains/example");

            link.Click();
            Assert.IsNotNull(b.CurrentState);
            Assert.AreEqual(b.Referer.ToString(), startingUrl);

            // This explicitly tests that a 300 redirect preserves the original referrer.
            Assert.AreEqual(b.CurrentState.Url.ToString(), "http://www.iana.org/domains/reserved");
            Assert.AreNotEqual(b.Referer.ToString(), targetHref);
        }
开发者ID:rodram,项目名称:SimpleBrowser,代码行数:26,代码来源:RefererHeader.cs

示例4: SampleApp

		public void SampleApp()
		{
			Browser b = new Browser(Helper.GetMoviesRequestMocker());
			HttpRequestLog lastRequest = null;
			b.RequestLogged += (br, l) =>
			{
				lastRequest = l;
			};
			b.Navigate("http://localhost/movies/");
			var link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
			link.Click();
			var box = b.Select("input[name=Title]");
			box.Value = "1234";
			box = b.Select("input[name=ReleaseDate]");
			box.Value = "2011-01-01";
			box = b.Select("input[name=Genre]");
			box.Value = "dark";
			box = b.Select("input[name=Price]");
			box.Value = "51";
			box = b.Select("input[name=Rating]");
			box.Value = "***";
			link = b.Select("input[type=submit]");
			link.Click();
			Assert.That(b.LastWebException == null, "Webexception detected");
			Assert.That(lastRequest.PostBody.Contains("&Price=51&"));

		}
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:27,代码来源:Issues.cs

示例5: Forms_Disabled_and_ReadOnly

        public void Forms_Disabled_and_ReadOnly()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.HTML5Elements.htm"));
            var textarea = b.Find("readonlytextarea");
            textarea.Value = "some value";
            Assert.IsTrue(textarea.Value == "readme textarea");
            Assert.IsTrue(textarea.ReadOnly);
            Assert.IsFalse(textarea.Disabled);

            textarea = b.Find("disabledtextarea");
            textarea.Value = "some value";
            Assert.IsTrue(textarea.Value == "disableme textarea");
            Assert.IsFalse(textarea.ReadOnly);
            Assert.IsTrue(textarea.Disabled);

            var textinput = b.Find("readonlytext");
            textinput.Value = "some value";
            Assert.IsTrue(textinput.Value == "readme");
            Assert.IsTrue(textinput.ReadOnly);
            Assert.IsFalse(textinput.Disabled);

            textinput = b.Find("disabledtext");
            textinput.Value = "some value";
            Assert.IsTrue(textinput.Value == "disableme");
            Assert.IsFalse(textinput.ReadOnly);
            Assert.IsTrue(textinput.Disabled);

            var checkbox = b.Find("disabledcheck");
            Assert.IsTrue(checkbox.Disabled);

            var radio = b.Find("disabledradio");
            Assert.IsTrue(radio.Disabled);

            HtmlResult disabledSubmit = b.Find("ds");
            Assert.IsTrue(disabledSubmit.Disabled);
            ClickResult clickResult = disabledSubmit.Click();
            Assert.IsTrue(clickResult == ClickResult.SucceededNoOp);

            HtmlResult submit = b.Find("es");
            Assert.IsFalse(submit.Disabled);
            clickResult = submit.Click();
            Assert.IsTrue(clickResult == ClickResult.SucceededNavigationComplete);

            // Check to make sure the form submitted.
            var names = b.Select("td.desc");
            var values = b.Select("td.val");
            Assert.IsTrue(names.Count() == values.Count());
            Assert.IsTrue(values.Where(e => e.Value == "readme textarea").FirstOrDefault() != null);

            // Now, validate that the disabled fields were not.
            Assert.IsTrue(values.Where(e => e.Value == "disableme textarea").FirstOrDefault() == null);
            Assert.IsTrue(values.Where(e => e.Value == "disableme").FirstOrDefault() == null);
            Assert.IsTrue(values.Where(e => e.Value == "disabledcheck").FirstOrDefault() == null);
            Assert.IsTrue(values.Where(e => e.Value == "disabledradio").FirstOrDefault() == null);
            Assert.IsTrue(values.Where(e => e.Value == "disabledselect").FirstOrDefault() == null);
        }
开发者ID:rodram,项目名称:SimpleBrowser,代码行数:57,代码来源:Forms.cs

示例6: Navigating_To_A_Url_With_Querystring_Parameters_Retains_Parameters

 public void Navigating_To_A_Url_With_Querystring_Parameters_Retains_Parameters()
 {
     Browser b = new Browser(Helper.GetMoviesRequestMocker());
     b.Navigate("http://localhost/movies/");
     var link = b.Find(ElementType.Anchor, FindBy.Text, "Rio Bravo");
     link.Click();
     Assert.AreEqual(new Uri("http://www.example.com/movie.html?id=4"), b.Url);
 }
开发者ID:Buildstarted,项目名称:SimpleBrowser,代码行数:8,代码来源:History.cs

示例7: Forms_Malformed_Select

        public void Forms_Malformed_Select()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));

            // Test the malformed option.
            HtmlResult options = b.Find("malformedOption1");
            Assert.IsNotNull(options);
            Assert.IsTrue(options.Exists);

            options.Value = "3";
            Assert.That(options.Value == "3");

            // Test the malformed option group
            IEnumerable<XElement> groups = options.XElement.Elements("optgroup");
            Assert.That(groups.Count() == 2);

            XElement group = groups.First();
            Assert.That(group.Elements("option").Count() == 4);

            group = groups.ElementAt(1);
            Assert.That(group.Elements("option").Count() == 3);

            options = b.Find("malformedOption2");
            Assert.IsNotNull(options);
            Assert.IsTrue(options.Exists);

            options.Value = "3";
            Assert.That(options.Value != "3");
            Assert.That(options.Value == "4");

            options.Value = "V";
            Assert.That(options.Value == "V");

            // Test the malformed option group
            groups = options.XElement.Elements("optgroup");
            Assert.That(groups.Count() == 2);

            group = groups.First();
            Assert.That(group.Elements("option").Count() == 2);

            group = groups.ElementAt(1);
            Assert.That(group.Elements("option").Count() == 5);
        }
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:44,代码来源:Forms.cs

示例8: PreElement

        public void PreElement()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.Elements.htm"));

            var preContent = b.Find("preTestElement");
            Assert.IsTrue(
                preContent.Value.Contains("space         \r\n            and") ||
                preContent.Value.Contains("space         \n            and"));
        }
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:10,代码来源:Parsing.cs

示例9: SearchingAnElementBySeveralSelectingMethods

        public void SearchingAnElementBySeveralSelectingMethods()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));

            var colorBox = b.Find("first-checkbox"); // find by id
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with ID first-checkbox");

            colorBox = b.Select("*[type=checkbox][checked]");
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with type checkbox and checked");
        }
开发者ID:bubish,项目名称:SimpleBrowser,代码行数:11,代码来源:Selectors.cs

示例10: When_Navigate_Back_Current_Url_Should_Change

		public void When_Navigate_Back_Current_Url_Should_Change()
		{
			Browser b = new Browser(Helper.GetMoviesRequestMocker());
			HttpRequestLog lastRequest = null;
			b.RequestLogged += (br, l) =>
			{
				lastRequest = l;
			};
			b.Navigate("http://localhost/movies/");
			Assert.That(b.Url == new Uri("http://localhost/movies/"));
			b.Navigate("http://localhost/movies2/");
			Assert.That(b.Url == new Uri("http://localhost/movies2/"));
			b.NavigateBack();
			Assert.AreEqual(new Uri("http://localhost/movies/"), b.Url);
			var link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
			Assert.NotNull(link, "After navigating back, the 'Create New' link should be found");
			b.NavigateForward();
			Assert.AreEqual(new Uri("http://localhost/movies2/"), b.Url);
			link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
			Assert.AreEqual(false, link.Exists, "After navigating forward, the 'Create New' link should NOT be found");
		}
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:21,代码来源:History.cs

示例11: SearchingAnInputElementBySeveralSelectingMethods

        public void SearchingAnInputElementBySeveralSelectingMethods()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));

            var colorBox = b.Find("colorBox"); // find by id
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with ID colorBox");

            colorBox = b.Find("input", new {name="colorBox", type="color"}); // find by attributes
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox and type color");

            colorBox = b.Find("input", new { name = "colorBox", type = "Color" }); // find by attributes
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox and type color");

            colorBox = b.Find("input", new { name = "colorBox", type = "Colors" }); // find by attributes
            Assert.That(colorBox.Exists == false, "There should be no element with name colorBox and type Colors");

            colorBox = b.Find(ElementType.TextField, new { name = "colorBox", type = "Color" }); // find by attributes
            Assert.That(colorBox.Count() == 0, "Input elements with types other than text, password and hidden should not be found");

            colorBox = b.Find("input", FindBy.Name, "colorBox"); // find by FindBy
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox");

            colorBox = b.Select("input[name=colorBox]"); // find by Css selector
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with name colorBox");

            colorBox = b.Select("input[type=color]"); // find by Css selector
            Assert.That(colorBox.Count() == 1, "There should be exactly 1 element with type color");

            colorBox = b.Select("input[type=Color]"); // find by Css selector
            Assert.That(colorBox.Count() == 0, "There should be no element for the expression input[type=Color] (CSS is case sensitive)");

            var clickLink = b.Select(".clickLink"); // find by Css selector
            Assert.That(clickLink.Count() == 1, "There should be one element for the expression .clickLink");
        }
开发者ID:bubish,项目名称:SimpleBrowser,代码行数:35,代码来源:Selectors.cs

示例12: HtmlElement_Cdata

        /// <summary>
        /// Tests the CDATA element
        /// </summary>
        public void HtmlElement_Cdata()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.CommentElements.htm"));
            b.Find("link1");

            var comments = from node in b.XDocument.Elements().DescendantNodesAndSelf()
                           where node.NodeType == XmlNodeType.CDATA
                           select node as XCData;

            var comment = comments.First();
            Assert.That(comment.ToString(), Is.EqualTo("<![CDATA[Some content]]>"));
        }
开发者ID:Buildstarted,项目名称:SimpleBrowser,代码行数:16,代码来源:CommentElements.cs

示例13: After_Navigating_Away_HtmlResult_Should_Throw_Exception

 public void After_Navigating_Away_HtmlResult_Should_Throw_Exception()
 {
     Browser b = new Browser(Helper.GetMoviesRequestMocker());
     HttpRequestLog lastRequest = null;
     b.RequestLogged += (br, l) =>
     {
         lastRequest = l;
     };
     b.Navigate("http://localhost/movies/");
     Assert.That(b.Url == new Uri("http://localhost/movies/"));
     var link = b.Find(ElementType.Anchor, FindBy.Text, "Create New");
     link.Click();
     Assert.AreEqual(new Uri("http://localhost/movies/Movies/Create?"), b.Url);
     Assert.Throws(typeof(InvalidOperationException), () => link.Click(), "Clicking the link should now throw an exception");
 }
开发者ID:bubish,项目名称:SimpleBrowser,代码行数:15,代码来源:History.cs

示例14: Navigating_IFrames_Using_Target

        public void Navigating_IFrames_Using_Target()
        {
            Browser b = new Browser(Helper.GetFramesMock());
            HttpRequestLog lastRequest = null;
            b.RequestLogged += (br, l) =>
            {
                lastRequest = l;
            };
            b.Navigate("http://localhost/");
            Assert.That(b.Frames.Count() == 2);
            Assert.That(b.Frames.First().Url == new Uri("http://localhost/subdirectory/frame.htm"));

            b.Find("framelink").Click();
            Assert.That(b.Frames.Count() == 2);
            Assert.That(b.Url == new Uri("http://localhost/"));
            Assert.That(b.Frames.First().Url == new Uri("http://localhost/bla.htm"));
        }
开发者ID:bubish,项目名称:SimpleBrowser,代码行数:17,代码来源:WindowsAndFrames.cs

示例15: When_Testing_Referer_DefaultMode_Secure_Transition

        public void When_Testing_Referer_DefaultMode_Secure_Transition()
        {
            string startingUrl = "https://www.example.com/";

            Browser b = new Browser();
            Assert.AreEqual(b.RefererMode, Browser.RefererModes.Default);

            b.Navigate(startingUrl);
            Assert.IsNotNull(b.CurrentState);
            Assert.IsNull(b.Referer);

            var link = b.Find(ElementType.Anchor, FindBy.Text, "More information...");
            Assert.IsNotNull(link);

            link.Click();
            Assert.IsNotNull(b.CurrentState);
            Assert.IsNull(b.Referer);
        }
开发者ID:rodram,项目名称:SimpleBrowser,代码行数:18,代码来源:RefererHeader.cs


注:本文中的Browser.Find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。