Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML Frame-related setters and getters #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions src/main/java/com/gargoylesoftware/htmlunit/WebClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,34 @@ public void setCurrentWindow(final WebWindow window) {
}
}
}

/**
* Set the current window to the original window instantiated by the browser
* (the earliest opened window).
*/
public void setFirstWindow() {
setCurrentWindow(topLevelWindows_.get(0));
}

/**
* Set the current window to a frame, identified by index.
*/
public void setCurrentFrame(final int index) throws IndexOutOfBoundsException {
HtmlPage page = (HtmlPage) getCurrentWindow().getEnclosedPage();
List<FrameWindow> frames = page.getFrames();
if (index >= frames.size())
throw new IndexOutOfBoundsException("Attempt to select frame " + index + " of " + frames.size() + " frames");
setCurrentWindow(frames.get(index));
}

/**
* Set the current window to a frame, identified by name.
*/
public void setCurrentFrame(final String name) throws ElementNotFoundException {
HtmlPage page = (HtmlPage) getCurrentWindow().getEnclosedPage();
FrameWindow frame = page.getFrameByName(name);
setCurrentWindow(frame);
}

/**
* Adds a listener for {@link WebWindowEvent}s. All events from all windows associated with this
Expand Down Expand Up @@ -1093,6 +1121,29 @@ public WebWindow getWebWindowByName(final String name) throws WebWindowNotFoundE

throw new WebWindowNotFoundException(name);
}

/**
* Get @{@code TopLevelWindow} or {@code DialogWindow} with the specified name.
*/
public WebWindow getTopLevelOrDialog(final String name) throws WebWindowNotFoundException {
WebAssert.notNull("name", name);

for (final WebWindow webWindow : windows_) {
if ((webWindow instanceof TopLevelWindow || webWindow instanceof DialogWindow ) && name.equals(webWindow.getName())) {
return webWindow;
}
}

throw new WebWindowNotFoundException(name);
}

/**
* Get the {@code FrameWindow}s within the current page.
*/
public List<FrameWindow> getFrames() {
HtmlPage page = (HtmlPage) getCurrentWindow().getEnclosedPage();
return page.getFrames();
}

/**
* <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
Expand Down