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


C# Browser.SetContent方法代码示例

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


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

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

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

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

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

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

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

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

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

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

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

示例13: Forms_Input_Types

        public void Forms_Input_Types()
        {
            // Initialize browser and load content.
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.SimpleForm.htm"));

            // Test ability to find HTML5 elements.
            // Find by ID.
            HtmlResult colorBox = b.Find("colorBox");
            Assert.IsNotNull(colorBox);
            Assert.IsTrue(colorBox.Exists);

            // Find by name.
            // Any undefined or unknown type is considered a text field.
            colorBox = b.Find(ElementType.TextField, FindBy.Name, "colorBox");
            Assert.IsNotNull(colorBox);
            Assert.IsTrue(colorBox.Exists);
        }
开发者ID:AshWilliams,项目名称:SimpleBrowser,代码行数:18,代码来源:Forms.cs

示例14: HtmlElement_Attributes

        public void HtmlElement_Attributes()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.CommentElements.htm"));
            HtmlResult result = b.Find("html1");

            Assert.IsTrue(result.Exists);
            Assert.AreEqual(result.XElement.Attributes().Count(), namespaceCount);

            List<XAttribute> attributes = new List<XAttribute>();
            attributes.AddRange(result.XElement.Attributes());

            for (int index = 0; index < namespaceCount; index++)
            {
                XAttribute attribute = attributes[index];
                switch (index)
                {
                    case 0:
                        {
                            Assert.IsTrue(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "xmlns");
                            Assert.AreEqual(attribute.Value, "http://www.w3.org/1999/xhtml");
                            break;
                        }

                    case 1:
                        {
                            Assert.IsFalse(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "lang");
                            Assert.AreEqual(attribute.Value, "en");
                            break;
                        }

                    case 2:
                        {
                            Assert.IsFalse(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "lang");
                            Assert.AreEqual(attribute.Value, "en");
                            Assert.AreEqual(attribute.Name.Namespace, XNamespace.Xml);
                            break;
                        }

                    case 3:
                        {
                            Assert.IsFalse(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "id");
                            Assert.AreEqual(attribute.Value, "html1");
                            break;
                        }

                    case 4:
                        {
                            Assert.IsFalse(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "class");
                            Assert.AreEqual(attribute.Value, "cookieBar");
                            break;
                        }

                    case 5:
                        {
                            Assert.IsTrue(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "fb");
                            Assert.AreEqual(attribute.Value, "http://www.facebook.com/2008/fbml");
                            Assert.AreEqual(attribute.Name.Namespace, XNamespace.Xmlns);
                            break;
                        }

                    case 6:
                        {
                            Assert.IsTrue(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "xsi");
                            Assert.AreEqual(attribute.Value, "http://www.w3.org/2001/XMLSchema-instance");
                            Assert.AreEqual(attribute.Name.Namespace, XNamespace.Xmlns);
                            break;
                        }

                    case 7:
                        {
                            Assert.IsFalse(attribute.IsNamespaceDeclaration);
                            Assert.AreEqual(attribute.Name.LocalName, "schemalocation");
                            Assert.AreEqual(attribute.Value, "http://namespaces.ordnancesurvey.co.uk/cmd/local/v1.1 http://www.ordnancesurvey.co.uk/oswebsite/xml/cmdschema/local/V1.1/CMDFeatures.xsd");

                            XAttribute parent_attribute = result.XElement.Attributes().FirstOrDefault(element => element.Name == XNamespace.Xmlns + "xsi");
                            Assert.IsNotNull(parent_attribute);
                            Assert.AreEqual(parent_attribute.Value, attribute.Name.Namespace.NamespaceName);

                            break;
                        }
                }
            }
        }
开发者ID:shi5588,项目名称:shi5588,代码行数:91,代码来源:Namespace.cs

示例15: HtmlElement_Script_Comment

        /// <summary>
        /// Tests a comment inside of a script element
        /// </summary>
        public void HtmlElement_Script_Comment()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("SimpleBrowser.UnitTests.SampleDocs.CommentElements.htm"));

            string text = b.Text;
            HtmlResult scriptElement = b.Find("script", new { type = "text/javascript" });
            if (scriptElement.Exists)
            {
                // Test that the script element has at least one child element.
                // (This test is of questionable usefulness.)
                Assert.That(scriptElement.XElement.DescendantNodes().Count() > 0, "Script element does not have a child element");

                // Test that the child element is a comment element.
                var comments = from node in scriptElement.XElement.DescendantNodes()
                               where node.NodeType == XmlNodeType.Comment
                               select node as XComment;

                Assert.That(comments.Count() > 0, "Script element does not have a child element");

                // Test that the child element contains the sample script text.
                var comment = comments.First().ToString().Replace('\r', ' ').Replace('\n', ' ');
                Assert.That(
                    comment.Equals(
                        "<!--      var theForm = document.forms['form1'];      if (!theForm) {          theForm = document.form1;      }      function __doPostBack(eventTarget, eventArgument) {          if (!theForm.onsubmit || (theForm.onsubmit() != false)) {              theForm.__EVENTTARGET.value = eventTarget;              theForm.__EVENTARGUMENT.value = eventArgument;              theForm.submit();          }      }  // -->"),
                    "The comment text does not match the expected value");

                // Test that content of the comment does not appear in the browser text.
                Assert.That(b.ContainsText("theForm") == false, "Script comment appears in the 'visible' browser text.");
                Assert.That(b.Text.Contains("theForm") == false, "Script comment appears in the 'visible' browser text.");
            }
            else
            {
                Assert.Fail("Unable to find script tag in sample content.");
            }
        }
开发者ID:Buildstarted,项目名称:SimpleBrowser,代码行数:39,代码来源:CommentElements.cs


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