Пример #1
0
        public void HtmlNode_InnerText()
        {
            var doc = new HtmlDocument();

            doc.AppendChild(doc.CreateText("abc"));
            Assert.Equal("abc", doc.InnerText);
        }
Пример #2
0
        public IDocument CreateHtmlDocument(String title)
        {
            var document = new HtmlDocument();

            document.AppendChild(new DocumentType(document, TagNames.Html));
            document.AppendChild(document.CreateElement(TagNames.Html));
            document.DocumentElement.AppendChild(document.CreateElement(TagNames.Head));

            if (!String.IsNullOrEmpty(title))
            {
                var titleElement = document.CreateElement(TagNames.Title);
                titleElement.AppendChild(document.CreateTextNode(title));
                document.Head !.AppendChild(titleElement);
            }

            document.DocumentElement.AppendChild(document.CreateElement(TagNames.Body));
            document.BaseUrl = _owner.BaseUrl;
            return(document);
        }
Пример #3
0
        public void HtmlHasRightBodyElement()
        {
            var document = new HtmlDocument();
            var root     = new HtmlHtmlElement(document);

            document.AppendChild(root);
            var body = new HtmlBodyElement(document);

            root.AppendChild(body);
            Assert.AreEqual(body, document.Body);
        }
Пример #4
0
        public void HtmlHasRightHeadElement()
        {
            var document = new HtmlDocument();
            var root     = new HtmlHtmlElement(document);

            document.AppendChild(root);
            var head = new HtmlHeadElement(document);

            root.AppendChild(head);
            Assert.AreEqual(head, document.Head);
        }
Пример #5
0
        public void HtmlCustomTitleGeneration()
        {
            var document = new HtmlDocument();
            var title    = "My Title";

            document.Title = title;
            Assert.AreEqual("", document.Title);
            var html = document.CreateElement(TagNames.Html);
            var head = document.CreateElement(TagNames.Head);

            document.AppendChild(html);
            html.AppendChild(head);
            document.Title = title;
            Assert.AreEqual(title, document.Title);
        }
Пример #6
0
        public void HtmlButtonToggleProperties()
        {
            var document = new HtmlDocument();
            var form     = document.CreateElement <IHtmlFormElement>();
            var element  = document.CreateElement <IHtmlButtonElement>();

            document.AppendChild(form);
            form.AppendChild(element);

            Assert.IsFalse(element.IsDisabled);
            Assert.IsFalse(element.IsDraggable);
            Assert.AreEqual(String.Empty, element.FormMethod);

            element.IsDisabled  = true;
            element.IsDraggable = true;
            element.FormMethod  = "get";

            Assert.IsTrue(element.IsDisabled);
            Assert.IsTrue(element.IsDraggable);
            Assert.AreEqual("get", element.FormMethod);
        }
        /// <summary>
        /// Loads the response as a plain text (formatted as HTML) document.
        /// </summary>
        protected static async Task <IDocument> LoadTextAsync(IBrowsingContext context, CreateDocumentOptions options, CancellationToken cancellationToken)
        {
            var document = new HtmlDocument(context, options.Source);

            document.Setup(options.Response, options.ContentType, options.ImportAncestor);
            context.NavigateTo(document);
            var root = document.CreateElement(TagNames.Html);
            var head = document.CreateElement(TagNames.Head);
            var body = document.CreateElement(TagNames.Body);
            var pre  = document.CreateElement(TagNames.Pre);

            document.AppendChild(root);
            root.AppendChild(head);
            root.AppendChild(body);
            body.AppendChild(pre);
            pre.SetAttribute(AttributeNames.Style, "word-wrap: break-word; white-space: pre-wrap;");
            await options.Source.PrefetchAllAsync(cancellationToken).ConfigureAwait(false);

            pre.TextContent = options.Source.Text;
            return(document);
        }