Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlPage#getDocumentElement()
The following examples show how to use
com.gargoylesoftware.htmlunit.html.HtmlPage#getDocumentElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaScriptFunctionJob.java From htmlunit with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final DomElement doc = page.getDocumentElement(); final Scriptable scriptable = page.getEnclosingWindow().getScriptableObject(); page.executeJavaScriptFunction(function_, scriptable, args_, doc); }
Example 2
Source File: HtmlUnitNekoHtmlParser.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Adds a body element to the current page, if necessary. Strictly speaking, this should * probably be done by NekoHTML. See the bug linked below. If and when that bug is fixed, * we may be able to get rid of this code. * * http://sourceforge.net/p/nekohtml/bugs/15/ * @param page * @param originalCall * @param checkInsideFrameOnly true if the original page had body that was removed by JavaScript */ private void addBodyToPageIfNecessary( final HtmlPage page, final boolean originalCall, final boolean checkInsideFrameOnly) { // IE waits for the whole page to load before initializing bodies for frames. final boolean waitToLoad = page.hasFeature(PAGE_WAIT_LOAD_BEFORE_BODY); if (page.getEnclosingWindow() instanceof FrameWindow && originalCall && waitToLoad) { return; } // Find out if the document already has a body element (or frameset). final Element doc = page.getDocumentElement(); boolean hasBody = false; for (Node child = doc.getFirstChild(); child != null; child = child.getNextSibling()) { if (child instanceof HtmlBody || child instanceof HtmlFrameSet) { hasBody = true; break; } } // If the document does not have a body, add it. if (!hasBody && !checkInsideFrameOnly) { final DomElement body = getFactory("body").createElement(page, "body", null); doc.appendChild(body); } // If this is IE, we need to initialize the bodies of any frames, as well. // This will already have been done when emulating FF (see above). if (waitToLoad) { for (final FrameWindow frame : page.getFrames()) { final Page containedPage = frame.getEnclosedPage(); if (containedPage != null && containedPage.isHtmlPage()) { addBodyToPageIfNecessary((HtmlPage) containedPage, false, false); } } } }
Example 3
Source File: JavaScriptFunctionJob.java From HtmlUnit-Android with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final DomElement doc = page.getDocumentElement(); final Scriptable scriptable = page.getEnclosingWindow().getScriptableObject(); page.executeJavaScriptFunction(function_, scriptable, new Object[0], doc); }
Example 4
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 4 votes |
/** * Asserts that the XPath matches. */ public void assertXPath(HtmlPage page, String xpath) { HtmlElement documentElement = page.getDocumentElement(); assertNotNull("There should be an object that matches XPath:" + xpath, DomNodeUtil.selectSingleNode(documentElement, xpath)); }
Example 5
Source File: KubernetesPipelineTest.java From kubernetes-plugin with Apache License 2.0 | 4 votes |
private void assertNotXPath(HtmlPage page, String xpath) { HtmlElement documentElement = page.getDocumentElement(); assertNull("There should not be an object that matches XPath:" + xpath, DomNodeUtil.selectSingleNode(documentElement, xpath)); }