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;
}
Aggregations