public interface Frame
Each web page loaded in the browser has a main (top-level) frame. The frame itself may have
child frames. When a web page is unloaded, its frame and all child frames are closed
automatically. Any attempt to work with an already closed frame will lead to the IllegalStateException
error.
Modifier and Type | Method and Description |
---|---|
Browser |
browser()
Returns the
Browser instance of this frame. |
java.util.List<Frame> |
children()
Returns the list of child frames or an empty list if this frame does not have any children.
|
java.util.Optional<Document> |
document()
Returns an
Optional that contains the DOM Document instance of the frame or
an empty Optional if the frame does not have a document. |
boolean |
execute(EditorCommand command)
Executes the given
command in the frame. |
<T> T |
executeJavaScript(java.lang.String javaScript)
Executes the given
javaScript code in the frame and returns the result of the
execution. |
void |
executeJavaScript(java.lang.String javaScript,
java.util.function.Consumer<?> callback)
Executes the given
javaScript code in the frame and returns the result of the
execution through the given callback . |
boolean |
hasSelection()
Returns
true if some content in this frame is selected. |
java.lang.String |
html()
Returns a string that represents content of the frame in the HTML format or an empty string
if the frame does not have a content or its content is empty.
|
PointInspection |
inspect(int x,
int y)
Inspects the given location on the web page containing this frame and returns the result of
the inspection.
|
PointInspection |
inspect(Point location)
Inspects the given
location on the web page containing this frame and returns the
result of the inspection. |
boolean |
isCommandEnabled(EditorCommand.Name commandName)
Returns
true if the command with the given commandName can be executed in the
frame. |
boolean |
isMain()
Returns
true if the frame is a main (top-level) frame in the browser. |
Json |
json()
Returns the
Json instance for this frame . |
void |
loadUrl(java.lang.String url)
Navigates the frame to a resource identified by the given
url . |
WebStorage |
localStorage()
Returns the
localStorage instance of this frame. |
java.lang.String |
name()
Returns a string that represent the name of the frame or an empty string if the frame does
not have a name.
|
java.util.Optional<Frame> |
parent()
Returns an
Optional that contains the parent Frame instance or an empty
Optional if the current frame is a main (top-level) frame and it does not have a
parent. |
void |
print()
Requests printing of the currently loaded web page in this frame.
|
RenderProcess |
renderProcess()
Returns a
RenderProcess associated with the current Frame instance. |
java.lang.String |
selectionAsHtml()
Returns a string that contains HTML of the selected content in the frame or an empty string
if there is no selection.
|
java.lang.String |
selectionAsText()
Returns a text representation of the selected content in the frame or an empty string if
there is no selection.
|
WebStorage |
sessionStorage()
Returns the
sessionStorage instance of this frame. |
java.lang.String |
text()
Returns the content of the frame and its sub-frames as plain text or an empty string if the
frame does not have content or its content is empty.
|
void |
viewSource()
Creates a new popup where the
view-source:<frame-url> URL is loaded to display HTML
source of the frame. |
Browser browser()
Browser
instance of this frame.boolean isMain()
true
if the frame is a main (top-level) frame in the browser.java.util.Optional<Frame> parent()
Optional
that contains the parent Frame
instance or an empty
Optional
if the current frame is a main (top-level) frame and it does not have a
parent.java.lang.IllegalStateException
- when the frame is closedjava.util.List<Frame> children()
java.lang.IllegalStateException
- when this frame is closedjava.lang.String selectionAsText()
java.lang.IllegalStateException
- when the frame is closedjava.lang.String selectionAsHtml()
java.lang.IllegalStateException
- when the frame is closedboolean hasSelection()
true
if some content in this frame is selected.java.lang.IllegalStateException
- when the frame is closedjava.util.Optional<Document> document()
Optional
that contains the DOM Document
instance of the frame or
an empty Optional
if the frame does not have a document.java.lang.IllegalStateException
- when the frame is closedjava.lang.String name()
java.lang.IllegalStateException
- when the frame is closedjava.lang.String html()
java.lang.IllegalStateException
- when the frame is closedjava.lang.String text()
Limitations:
display:none
, unexpanded divs, etc.
Please note that this functionality is resource-intensive, consuming significant memory and CPU during a text capture.
java.lang.IllegalStateException
- when the frame is closedvoid viewSource()
view-source:<frame-url>
URL is loaded to display HTML
source of the frame.java.lang.IllegalStateException
- when the frame is closedvoid loadUrl(java.lang.String url)
url
. This method tells the
frame to start asynchronous loading and returns immediately.url
- URL of the resource to loadjava.lang.IllegalArgumentException
- when url
is empty or blankjava.lang.IllegalStateException
- when the frame is closed@Nullable <T> T executeJavaScript(java.lang.String javaScript)
javaScript
code in the frame and returns the result of the
execution.
Important: The method blocks the current thread execution and waits until the passed JavaScript code has been executed completely. The time required to complete the execution can be different depending on the passed JavaScript code. So, it is strongly recommended that the method is not invoked in the application UI thread.
T
- one of the following types: java.lang.Boolean
, java.lang.Double
, java.lang.String
, JsObject
, EventTarget
, or java.lang.Object
javaScript
- a string that represents JavaScript code to executenull
if the result of the execution on
JavaScript is null
or undefined
java.lang.IllegalStateException
- when the frame is closedjava.lang.IllegalArgumentException
- when javaScript
is emptyvoid executeJavaScript(java.lang.String javaScript, java.util.function.Consumer<?> callback)
javaScript
code in the frame and returns the result of the
execution through the given callback
.
This method does not block the current thread execution and executes the given JavaScript code asynchronously.
javaScript
- a string that represents JavaScript code to executecallback
- a callback you can use to get the result of the execution. The result can
be one of the following types: java.lang.Boolean
, java.lang.Double
, java.lang.String
, JsObject
, EventTarget
, or java.lang.Object
java.lang.IllegalStateException
- when the frame is closedjava.lang.IllegalArgumentException
- when javaScript
is emptyboolean execute(EditorCommand command)
command
in the frame.
Before executing the command it is recommended to check whether it can be executed or not
using the isCommandEnabled(EditorCommand.Name)
method.
command
- the command to executetrue
if the command has been executed successfullyjava.lang.IllegalStateException
- when the frame is closedisCommandEnabled(EditorCommand.Name)
boolean isCommandEnabled(EditorCommand.Name commandName)
true
if the command with the given commandName
can be executed in the
frame.
Some commands can be executed only under certain conditions. For example, the EditorCommand.Name.INSERT_TEXT
command can be executed only if there is a focused text field
in the frame.
commandName
- the name of the command to checkjava.lang.IllegalStateException
- when the frame is closedPointInspection inspect(Point location)
location
on the web page containing this frame and returns the
result of the inspection.location
- a point on the web pagejava.lang.IllegalStateException
- when the frame is closedPointInspection inspect(int x, int y)
x
- a horizontal coordinate on the web pagey
- a vertical coordinate on the web pagejava.lang.IllegalStateException
- when the frame is closedWebStorage localStorage()
localStorage
instance of this frame.java.lang.IllegalStateException
- when the frame is closedWebStorage sessionStorage()
sessionStorage
instance of this frame.java.lang.IllegalStateException
- when the frame is closedvoid print()
java.lang.IllegalStateException
- when the frame is closedJson json()
Json
instance for this frame
.java.lang.IllegalStateException
- when the frame is closedRenderProcess renderProcess()
RenderProcess
associated with the current Frame instance. When Chromium
loads a new web page, it creates a new render process where DOM and JavaScript are running.
This render process can be terminated by Chromium engine when a new web page with different
domain is loaded. So, this method can return different render process information.