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


C# Browser.Select方法代码示例

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


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

示例1: 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

示例2: 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

示例3: When_Setting_GZip_Encoding_Content_Should_Still_Be_Returned_As_Text

 public void When_Setting_GZip_Encoding_Content_Should_Still_Be_Returned_As_Text()
 {
     Browser b = new Browser();
     b.UseGZip = true;
     HttpRequestLog lastRequest = null;
     b.RequestLogged += (br, l) =>
     {
         lastRequest = l;
     };
     b.Navigate("http://www.facebook.com/");
     Assert.That(b.Url.Host == "www.facebook.com");
     Assert.That(b.Select("Title") != null);
     Assert.That(b.Select("Title").Value.IndexOf("Facebook", StringComparison.OrdinalIgnoreCase) > -1);
 }
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:14,代码来源:VerifyGZipEncoding.cs

示例4: UsePlusSelector

 public void UsePlusSelector()
 {
     Browser b = new Browser();
     b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));
     var inputDirectlyUnderForm = b.Select("div + input");
     Assert.That(inputDirectlyUnderForm.Count() == 1); // only one <input> comes directly after a div
 }
开发者ID:Buildstarted,项目名称:SimpleBrowser,代码行数:7,代码来源:Selectors.cs

示例5: HtmlElement_DecodedValue

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

            var div = b.Select("div");
            Assert.That(div.DecodedValue, Is.EqualTo("£ sign"));
        }
开发者ID:aqueduct,项目名称:SimpleBrowser,代码行数:8,代码来源:DecodedValue.cs

示例6: Uploading_A_File_With_Enctype_MultipartMime

		public void Uploading_A_File_With_Enctype_MultipartMime()
		{
			Browser b = new Browser(Helper.GetAllways200RequestMocker());
			b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.FileUpload.htm"));
			HttpRequestLog lastLog = null;
			b.RequestLogged += (br, l) =>
				{
					lastLog = l;
				};
			var form = b.Select("form");
			var file = b.Select("input[name=theFile]");
			DirectoryInfo dir = new FileInfo(Assembly.GetCallingAssembly().Location).Directory;
			file.Value = dir.GetFiles()[3].FullName;
			form.SubmitForm();

			Assert.NotNull(lastLog);
			Assert.That(lastLog.Method == "POST");
		}
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:18,代码来源:Uploading.cs

示例7: SearchingAnInputElementBySeveralSelectingMethods

        public void SearchingAnInputElementBySeveralSelectingMethods()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.FileUpload.htm"));
            HttpRequestLog lastLog = null;
            b.RequestLogged += (br, l) =>
                {
                    lastLog = l;
                };
            var form = b.Select("form");
            var file = b.Select("input[name=theFile]");
            DirectoryInfo dir = new FileInfo(Assembly.GetCallingAssembly().Location).Directory;
            file.Value = dir.GetFiles()[3].FullName;
            form.SubmitForm();

            Assert.NotNull(lastLog);
            Assert.That(lastLog.Method == "POST");
        }
开发者ID:spoike,项目名称:SimpleBrowser,代码行数:18,代码来源:Uploading.cs

示例8: HtmlElement_DecodedValue_MalformedDocument

        public void HtmlElement_DecodedValue_MalformedDocument()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.DecodedValue-malformed.htm"));

            var div = b.Select("div");
            Assert.That(div.ToList()[0].DecodedValue, Is.EqualTo("Blah £ sign üü"));
            Assert.That(div.ToList()[1].DecodedValue, Is.EqualTo("£ sign"));
            Assert.That(div.ToList()[2].DecodedValue, Is.EqualTo("üü"));
        }
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:10,代码来源:DecodedValue.cs

示例9: CanLoadHtmlFromFile

 public void CanLoadHtmlFromFile()
 {
     Regex start = new Regex("^([a-z]):\\\\");
     var b = new Browser();
     var f = new FileInfo(".\\SampleDocs\\movies1.htm");
     string uri = start.Replace(f.FullName, "file:///$1/");
     uri = uri.Replace("\\", "/");
     b.Navigate(uri);
     Assert.AreEqual(b.Select("ul#menu>li").Count(), 3, "Not loaded");
 }
开发者ID:abhaypsingh,项目名称:SimpleBrowser,代码行数:10,代码来源:FileUri.cs

示例10: CanLoadHtmlFromFile

		public void CanLoadHtmlFromFile()
		{
			var f = new FileInfo(".\\SampleDocs\\movies1.htm");
			string uri = string.Format("file:///{0}", f.FullName);
			uri = uri.Replace("\\", "/");

			var b = new Browser();
			b.Navigate(uri);
			Assert.AreEqual(b.Select("ul#menu>li").Count(), 3, "Not loaded");
		}
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:10,代码来源:FileUri.cs

示例11: 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

示例12: CanLoadHtmlFromFilesWithAbsolutePath

		public void CanLoadHtmlFromFilesWithAbsolutePath()
		{
			if (Directory.Exists("C:\\Windows\\Temp"))
			{
				File.Copy("SampleDocs\\movies1.htm", "C:\\Windows\\Temp\\movies1.htm", true);

				var b = new Browser();
				b.Navigate("file:///c:/Windows/Temp/movies1.htm");
				Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);

				b.Navigate("file:///c|/Windows/Temp/movies1.htm");
				Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);

				b.Navigate("file:///c|\\Windows\\Temp\\movies1.htm");
				Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);

				b.Navigate("file://\\c|\\Windows\\Temp\\movies1.htm");
				Assert.AreEqual(b.Select("ul#menu>li").Count(), 3);
			}
		}
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:20,代码来源:FileUri.cs

示例13: 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

示例14: GetAttribute_Backdoor_FrameHandle

 public void GetAttribute_Backdoor_FrameHandle()
 {
     Browser b = new Browser(Helper.GetFramesMock());
     HttpRequestLog lastRequest = null;
     b.RequestLogged += (br, l) =>
     {
         lastRequest = l;
     };
     b.Navigate("http://localhost/");
     var elm = b.Select("iframe");
     string handle = elm.GetAttribute("SimpleBrowser.WebDriver:frameWindowHandle");
     Assert.AreEqual(handle, "frame1");
 }
开发者ID:bubish,项目名称:SimpleBrowser,代码行数:13,代码来源:WindowsAndFrames.cs

示例15: Forms_Form_Attribute

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

            // This test covers the following cases:
            // 1. An input outside of the form with the form attribute is submitted.
            // 2. An input in another form with the form attribute is submitted.
            var field1 = b.Find("field1");
            field1.Value = "Name1";

            var field1a = b.Find("field1a");
            field1a.Value = "Name1a";

            var field2 = b.Find("field2");
            field2.Value = "Name2";

            var submit1 = b.Find("submit1");
            ClickResult clickResult = submit1.Click();

            // Check to make sure the form submitted.
            Assert.IsTrue(clickResult == ClickResult.SucceededNavigationComplete);

            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 == "Name1").FirstOrDefault() != null);
            Assert.IsTrue(values.Where(e => e.Value == "Name2").FirstOrDefault() != null);
            Assert.IsTrue(values.Where(e => e.Value == "Name1a").FirstOrDefault() != null);
            Assert.IsTrue(values.Where(e => e.Value == "Submit1").FirstOrDefault() != null);

            // This test covers the following cases:
            // 1. An input in the form with a form element corresponding to another form is not submitted.
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.HTML5Elements.htm"));

            field2 = b.Find("field2");
            field2.Value = "Name2";

            var field2a = b.Find("field2a");
            field2a.Value = "Name2a";

            var submit2 = b.Find("submit2");
            clickResult = submit2.Click();

            // Check to make sure the form submitted.
            Assert.IsTrue(clickResult == ClickResult.SucceededNavigationComplete);

            names = b.Select("td.desc");
            values = b.Select("td.val");
            Assert.IsTrue(values.Where(e => e.Value == "Submit2").FirstOrDefault() != null);
            Assert.IsTrue(values.Where(e => e.Value == "Name2a").FirstOrDefault() != null);
            Assert.IsFalse(values.Where(e => e.Value == "Name2").FirstOrDefault() != null);
        }
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:53,代码来源:Forms.cs


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