Search in sources :

Example 1 with HtmlFrame

use of com.gargoylesoftware.htmlunit.html.HtmlFrame in project htmlunit by HtmlUnit.

the class HTMLCollectionFrames method getWithFallback.

/**
 * To be called when the property detection fails in normal scenarios.
 *
 * @param name the name
 * @return the found object, or {@link Scriptable#NOT_FOUND}
 */
public Object getWithFallback(final String name) {
    Object result = NOT_FOUND;
    final DomNode domNode = getDomNodeOrNull();
    if (domNode != null) {
        // May be attempting to retrieve a frame by name.
        final HtmlPage page = (HtmlPage) domNode.getPage();
        result = getFrameWindowByName(page, name);
        if (result == NOT_FOUND) {
            result = getElementsByName(page, name);
            if (result == NOT_FOUND) {
                // May be attempting to retrieve element by ID (try map-backed operation again instead of XPath).
                try {
                    final HtmlElement htmlElement = page.getHtmlElementById(name);
                    if (getBrowserVersion().hasFeature(JS_WINDOW_FRAME_BY_ID_RETURNS_WINDOW) && htmlElement instanceof HtmlFrame) {
                        final HtmlFrame frame = (HtmlFrame) htmlElement;
                        result = getScriptableFor(frame.getEnclosedWindow());
                    } else {
                        result = getScriptableFor(htmlElement);
                    }
                } catch (final ElementNotFoundException e) {
                    result = NOT_FOUND;
                }
            }
        }
        if (result instanceof Window) {
            final WebWindow webWindow = ((Window) result).getWebWindow();
            result = getProxy(webWindow);
        }
    }
    return result;
}
Also used : WebWindow(com.gargoylesoftware.htmlunit.WebWindow) DialogWindow(com.gargoylesoftware.htmlunit.DialogWindow) TopLevelWindow(com.gargoylesoftware.htmlunit.TopLevelWindow) FrameWindow(com.gargoylesoftware.htmlunit.html.FrameWindow) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) HtmlObject(com.gargoylesoftware.htmlunit.html.HtmlObject) ElementNotFoundException(com.gargoylesoftware.htmlunit.ElementNotFoundException) HtmlFrame(com.gargoylesoftware.htmlunit.html.HtmlFrame) WebWindow(com.gargoylesoftware.htmlunit.WebWindow)

Aggregations

DialogWindow (com.gargoylesoftware.htmlunit.DialogWindow)1 ElementNotFoundException (com.gargoylesoftware.htmlunit.ElementNotFoundException)1 TopLevelWindow (com.gargoylesoftware.htmlunit.TopLevelWindow)1 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)1 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)1 FrameWindow (com.gargoylesoftware.htmlunit.html.FrameWindow)1 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)1 HtmlFrame (com.gargoylesoftware.htmlunit.html.HtmlFrame)1 HtmlObject (com.gargoylesoftware.htmlunit.html.HtmlObject)1 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)1 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)1