| SeleniumSession | R Documentation |
This class represents the client to a Selenium session. It will only work
if a Selenium server instance is running. If you get an error, use
selenium_server_available() to check if a server is running. See the
package README for more information, or use selenium_server() to try and
start a server automatically.
idThe id of the session, generated when the session is started.
browserThe browser that the session is using.
portThe port that the session is using.
hostThe host that the session is running on.
new()Create a Selenium session: opening a browser which can be controlled by the Selenium client.
SeleniumSession$new( browser = "firefox", port = 4444L, host = "localhost", verbose = FALSE, capabilities = NULL, request_body = NULL, timeout = 20 )
browserThe name of the browser to use (e.g. "chrome", "firefox", "edge").
portThe port that the Selenium server is using, so we can connect to it.
hostThe host that the Selenium server is running on. This is usually 'localhost' (i.e. your own machine).
verboseWhether to print the web requests that are being sent and any responses.
capabilitiesA list of capabilities to pass to the Selenium
server, to combine with the defaults generated using browser.
See chrome_options(), firefox_options(), and edge_options().
request_bodyA list of request body parameters to pass to the
Selenium server. Overrides capabilities.
timeoutHow long to wait for a request to receive a response before throwing an error.
A SeleniumSession object.
\dontrun{
session <- SeleniumSession$new(verbose = TRUE)
session$close()
}
create_webelement()Create a WebElement object using the parameters of the current session.
SeleniumSession$create_webelement(id)
idThe element id.
A WebElement object.
\dontrun{
session <- SeleniumSession$new()
element <- session$find_element(using = "css selector", value = "*")
element2 <- session$create_webelement(id = element$id)
session$close()
}
create_shadowroot()Create a ShadowRoot object using the parameters of the current session.
SeleniumSession$create_shadowroot(id)
idThe shadow root id.
A ShadowRoot object.
\dontrun{
session <- SeleniumSession$new()
shadow_root <- session$create_shadowroot(id = "foo")
session$close()
}
close()Close the current session. Once a session is closed, its methods will no longer work. However, the Selenium server will still be running.
SeleniumSession$close(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
TRUE if the session was closed successfully, or FALSE if the
session was already closed.
\dontrun{
session <- SeleniumSession$new()
session$close()
}
status()Get the status of the Selenium server. Unlike all other methods, this
method is independent of the session itself (meaning it can be used
even after SeleniumSession$close() is called). It is
identical to get_server_status(), but uses the host, port and verbose
options passed to the session, for convenience.
SeleniumSession$status(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
A list that can (but may not always) contain the following fields:
ready: Whether the server is ready to be connected to. This should
always be returned by the server.
message: A message about the status of the server.
uptime: How long the server has been running.
nodes: Information about the slots that the server can take.
\dontrun{
session <- SeleniumSession$new()
session$status()
session$close()
session$status()
}
get_timeouts()Get the timeouts of the current session. There are three types of timeouts:
session script timeout: The amount of time that the server will wait for scripts to run. Defaults to 3 seconds.
page load timeout: The amount of time that the server will wait for the page to load. Defaults to 30 seconds.
implicit wait: The amount of time that the server will wait for elements to be located, or for elements to become interactable when required. Defaults to 0 seconds.
SeleniumSession$get_timeouts(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
A list with three items: script, page_load, and implicit.
\dontrun{
session <- SeleniumSession$new()
session$get_timeouts()
session$close()
}
set_timeouts()Set the timeouts of the current session. The types of timeouts are
defined in SeleniumSession$get_timeouts().
SeleniumSession$set_timeouts( script = NULL, page_load = NULL, implicit_wait = NULL, request_body = NULL, timeout = 20 )
scriptThe amount of time to wait for scripts. By default, this is not set.
page_loadThe amount of time to wait for the page to load.
implicit_waitThe amount of time to wait for elements on the page.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$set_timeouts(script = 100)
session$get_timeouts()
session$close()
}
navigate()Navigate to a URL.
SeleniumSession$navigate(url, request_body = NULL, timeout = 20)
urlThe URL to navigate to. Must begin with a protocol (e.g. 'https://').
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request.
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$close()
}
current_url()Get the current URL.
SeleniumSession$current_url(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The URL of the current page.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$current_url()
session$close()
}
back()Go back in the navigation history.
SeleniumSession$back(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$navigate("https://www.tidyverse.org")
session$back()
session$current_url()
session$close()
}
forward()Go forward in the navigation history.
SeleniumSession$forward(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$navigate("https://www.tidyverse.org")
session$back()
session$forward()
session$current_url()
session$close()
}
refresh()Reload the current page.
SeleniumSession$refresh(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$refresh()
session$close()
}
title()Get the title of the current page.
SeleniumSession$title(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The title of the current page.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$title()
session$close()
}
window_handle()Get the current window handle.
SeleniumSession$window_handle(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The handle of the current window (a string).
\dontrun{
session <- SeleniumSession$new()
session$window_handle()
session$close()
}
close_window()Close the current window.
SeleniumSession$close_window(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$new_window()
session$close_window()
session$close()
}
switch_to_window()Switch to a specific window.
SeleniumSession$switch_to_window(handle, request_body = NULL, timeout = 20)
handleThe handle of the window to switch to.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
handle <- session$window_handle()
handle2 <- session$new_window()$handle
session$switch_to_window(handle)
session$switch_to_window(handle2)
session$close()
}
window_handles()Get the handles of all open windows.
SeleniumSession$window_handles(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The handles of all open windows (a list of strings).
\dontrun{
session <- SeleniumSession$new()
handles <- session$window_handles()
session$close()
}
new_window()Create a new window. Note that this window is not automatically switched to.
SeleniumSession$new_window(
type = c("tab", "window"),
request_body = NULL,
timeout = 20
)typeWhether to create a tab or a window.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
A list containing two elements:
handle: The handle of the new window.
type: The type of window. ("tab" or "window").
\dontrun{
session <- SeleniumSession$new()
handle <- session$new_window()$handle
session$switch_to_window(handle)
session$close()
}
switch_to_frame()Frames allow you to split a window into multiple sections, where each section can load a separate HTML document. This function allows you to switch to a specific frame, given its ID, meaning that frame will become the current browsing context.
SeleniumSession$switch_to_frame(id = NA, request_body = NULL, timeout = 20)
idThe ID of the frame to switch to. By default, the top-level browsing context is switched to (i.e. not a frame). This can also be a WebElement object, in which case the frame that contains said element will be switched to.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$switch_to_frame()
session$close()
}
switch_to_parent_frame()Switch to the parent frame of the current frame.
SeleniumSession$switch_to_parent_frame(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$switch_to_frame()
session$switch_to_parent_frame()
session$close()
}
get_window_rect()Get the size and position of the current window.
SeleniumSession$get_window_rect(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
A list containing four elements:
x: The x position of the window relative to the left of the screen.
y: The y position of the window relative to the top of the screen.
width: The width of the window.
height: The height of the window.
\dontrun{
session <- SeleniumSession$new()
session$get_window_rect()
session$close()
}
set_window_rect()Set the size and position of the current window.
SeleniumSession$set_window_rect( width = NULL, height = NULL, x = NULL, y = NULL, request_body = NULL, timeout = 20 )
widthThe width of the window.
heightThe height of the window.
xThe x position of the window relative to the left of the screen.
yThe y position of the window relative to the top of the screen.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$set_window_rect(width = 800, height = 600, x = 2, y = 3)
session$close()
}
maximize_window()Maximize the current window. This makes the window the maximum size it can be, without being full screen.
SeleniumSession$maximize_window(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$maximize_window()
session$close()
}
minimize_window()Minimize the current window. This hides the window.
SeleniumSession$minimize_window(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$minimize_window()
session$close()
}
fullscreen_window()Make the window full screen.
SeleniumSession$fullscreen_window(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$fullscreen_window()
session$close()
}
get_active_element()Get the currently active element.
SeleniumSession$get_active_element(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
A WebElement object.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$get_active_element()
session$close()
}
find_element()Find the first element matching a selector.
SeleniumSession$find_element(
using = c("css selector", "xpath", "tag name", "link text", "partial link text"),
value,
request_body = NULL,
timeout = 20
)usingThe type of selector to use.
valueThe value of the selector: a string.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
A WebElement object.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$find_element(using = "css selector", value = "#download")
session$find_element(using = "xpath", value = "//div[contains(@class, 'col-xs')]/h1")
session$close()
}
find_elements()Find all elements matching a selector.
SeleniumSession$find_elements(
using = c("css selector", "xpath", "tag name", "link text", "partial link text"),
value,
request_body = NULL,
timeout = 20
)usingThe type of selector to use.
valueThe value of the selector: a string.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
A list of WebElement objects.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$find_elements(using = "css selector", value = "h1")
session$find_elements(using = "xpath", value = "//h1")
session$close()
}
get_page_source()Get the HTML source of the current page, serialized as a string.
SeleniumSession$get_page_source(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
A string.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$get_page_source()
session$close()
}
execute_script()Execute a JavaScript script.
SeleniumSession$execute_script(x, ..., request_body = NULL, timeout = 20)
xThe script to execute. To return a value, do so explicitly,
e.g. return 1.
...Additional arguments to pass to the script. These can be
accessed in the script using the arguments array. Can be WebElement
objects or lists of such objects, which will be converted to nodes.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The return value of the script. Nodes or lists of nodes will be converted to WebElement objects.
\dontrun{
session <- SeleniumSession$new()
session$execute_script("return 1")
session$execute_script("return arguments[0] + arguments[1]", 1, 2)
element <- session$find_element(value = "*")
session$execute_script("return arguments[0]", element)
session$close()
}
execute_async_script()Execute an asynchronous JavaScript script, waiting for a value to be returned.
SeleniumSession$execute_async_script(x, ..., request_body = NULL, timeout = 20)
xThe script to execute. Unlike execute_script(). You return
an value using the callback function, which can be accessed using
arguments[arguments.length - 1]. For example, to return 1, you
would write arguments[arguments.length - 1](1). This allows you to
write asynchronous JavaScript, but treat it like synchronous R code.
...Additional arguments to pass to the script. Can be WebElement objects or lists of such objects, which will be converted to nodes.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The return value of the script. Nodes or lists of nodes will be converted to WebElement objects.
\dontrun{
session <- SeleniumSession$new()
session$execute_async_script("
let callback = arguments[arguments.length - 1];
callback(1)
")
session$close()
}
get_cookies()Get all cookies.
SeleniumSession$get_cookies(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
A list of cookies. Each cookie is a list with a name and
value field, along with some other optional fields.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$get_cookies()
session$close()
}
get_cookie()Get a specific cookie using its name.
SeleniumSession$get_cookie(name, request_body = NULL, timeout = 20)
nameThe name of the cookie.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The cookie object.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$add_cookie(list(name = "foo", value = "bar"))
session$get_cookie("foo")
session$close()
}
add_cookie()Add a cookie to the cookie store of the current document.
SeleniumSession$add_cookie(cookie, request_body = NULL, timeout = 20)
cookieThe cookie object to add: a list which must contain a
name and value field.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$add_cookie(list(name = "my_cookie", value = "1"))
session$close()
}
delete_cookie()Delete a cookie using its name.
SeleniumSession$delete_cookie(name, request_body = NULL, timeout = 20)
nameThe name of the cookie.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$add_cookie(list(name = "foo", value = "bar"))
session$delete_cookie("foo")
session$close()
}
delete_all_cookies()Delete all cookies in the cookie store of the current document.
SeleniumSession$delete_all_cookies(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$delete_all_cookies()
session$close()
}
perform_actions()Perform a sequence of actions.
SeleniumSession$perform_actions( actions, release_actions = TRUE, request_body = NULL, timeout = 20 )
actionsA selenium_actions_stream object, created using
actions_stream().
release_actionsWhether to call release_actions() after
performing the actions.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
actions <- actions_stream(
actions_press(keys$enter),
actions_pause(0.5),
actions_release(keys$enter)
)
session$perform_actions(actions)
session$close()
}
release_actions()Release all keys and pointers that were pressed using
perform_actions().
SeleniumSession$release_actions(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
actions <- actions_stream(
actions_press("a")
)
session$perform_actions(actions, release_actions = FALSE)
session$release_actions()
session$close()
}
dismiss_alert()Dismiss the current alert, if present.
SeleniumSession$dismiss_alert(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$execute_script("alert('hello')")
session$dismiss_alert()
session$close()
}
accept_alert()Accept the current alert, if present.
SeleniumSession$accept_alert(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$execute_script("alert('hello')")
session$accept_alert()
session$close()
}
get_alert_text()Get the message of the current alert, if present.
SeleniumSession$get_alert_text(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The message of the current alert (a string).
\dontrun{
session <- SeleniumSession$new()
session$execute_script("alert('hello')")
session$get_alert_text()
session$close()
}
send_alert_text()Send text to the current alert, if present. Useful if the alert is a prompt.
SeleniumSession$send_alert_text(text, request_body = NULL, timeout = 20)
textThe text to send.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The session object, invisibly.
\dontrun{
session <- SeleniumSession$new()
session$execute_script("prompt('Enter text:')")
session$send_alert_text("hello")
session$close()
}
screenshot()Take a screenshot of the current page.
SeleniumSession$screenshot(timeout = 20)
timeoutHow long to wait for a request to receive a response before throwing an error.
The base64-encoded PNG screenshot, as a string.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$screenshot()
session$close()
}
print_page()Render the current page as a PDF.
SeleniumSession$print_page(
orientation = c("portrait", "landscape"),
scale = 1,
background = FALSE,
width = NULL,
height = NULL,
margin = NULL,
footer = NULL,
header = NULL,
shrink_to_fit = NULL,
page_ranges = NULL,
request_body = NULL,
timeout = 20
)orientationThe page orientation, either "portrait" or
"landscape".
scaleThe page scale, a number between 0.1 and 2.
backgroundWhether to print the background of the page.
widthThe page width, in inches.
heightThe page height, in inches.
marginThe page margin, in inches. Either a number, in which case
the margin on all sides are set to that value, or a list of four
numbers, with names left, right, top, and bottom, in which
case the margin on each side is set individually.
footerThe page footer, as a string.
headerThe page header, as a string.
shrink_to_fitWhether to shrink the page to fit the width and height.
page_rangesA list of page ranges (e.g. "1", "1-3") to print.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
The base64-encoded PDF, as a string.
\dontrun{
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$print_page()
session$close()
}
clone()The objects of this class are cloneable with this method.
SeleniumSession$clone(deep = FALSE)
deepWhether to make a deep clone.
## ------------------------------------------------
## Method `SeleniumSession$new`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new(verbose = TRUE)
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$create_webelement`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
element <- session$find_element(using = "css selector", value = "*")
element2 <- session$create_webelement(id = element$id)
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$create_shadowroot`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
shadow_root <- session$create_shadowroot(id = "foo")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$close`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$status`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$status()
session$close()
session$status()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$get_timeouts`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$get_timeouts()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$set_timeouts`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$set_timeouts(script = 100)
session$get_timeouts()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$navigate`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$current_url`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$current_url()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$back`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$navigate("https://www.tidyverse.org")
session$back()
session$current_url()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$forward`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$navigate("https://www.tidyverse.org")
session$back()
session$forward()
session$current_url()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$refresh`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$refresh()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$title`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$title()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$window_handle`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$window_handle()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$close_window`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$new_window()
session$close_window()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$switch_to_window`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
handle <- session$window_handle()
handle2 <- session$new_window()$handle
session$switch_to_window(handle)
session$switch_to_window(handle2)
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$window_handles`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
handles <- session$window_handles()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$new_window`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
handle <- session$new_window()$handle
session$switch_to_window(handle)
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$switch_to_frame`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$switch_to_frame()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$switch_to_parent_frame`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$switch_to_frame()
session$switch_to_parent_frame()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$get_window_rect`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$get_window_rect()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$set_window_rect`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$set_window_rect(width = 800, height = 600, x = 2, y = 3)
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$maximize_window`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$maximize_window()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$minimize_window`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$minimize_window()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$fullscreen_window`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$fullscreen_window()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$get_active_element`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$get_active_element()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$find_element`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$find_element(using = "css selector", value = "#download")
session$find_element(using = "xpath", value = "//div[contains(@class, 'col-xs')]/h1")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$find_elements`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$find_elements(using = "css selector", value = "h1")
session$find_elements(using = "xpath", value = "//h1")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$get_page_source`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$get_page_source()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$execute_script`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$execute_script("return 1")
session$execute_script("return arguments[0] + arguments[1]", 1, 2)
element <- session$find_element(value = "*")
session$execute_script("return arguments[0]", element)
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$execute_async_script`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$execute_async_script("
let callback = arguments[arguments.length - 1];
callback(1)
")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$get_cookies`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$get_cookies()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$get_cookie`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$add_cookie(list(name = "foo", value = "bar"))
session$get_cookie("foo")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$add_cookie`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$add_cookie(list(name = "my_cookie", value = "1"))
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$delete_cookie`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$add_cookie(list(name = "foo", value = "bar"))
session$delete_cookie("foo")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$delete_all_cookies`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$delete_all_cookies()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$perform_actions`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
actions <- actions_stream(
actions_press(keys$enter),
actions_pause(0.5),
actions_release(keys$enter)
)
session$perform_actions(actions)
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$release_actions`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
actions <- actions_stream(
actions_press("a")
)
session$perform_actions(actions, release_actions = FALSE)
session$release_actions()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$dismiss_alert`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$execute_script("alert('hello')")
session$dismiss_alert()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$accept_alert`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$execute_script("alert('hello')")
session$accept_alert()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$get_alert_text`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$execute_script("alert('hello')")
session$get_alert_text()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$send_alert_text`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$execute_script("prompt('Enter text:')")
session$send_alert_text("hello")
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$screenshot`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$screenshot()
session$close()
## End(Not run)
## ------------------------------------------------
## Method `SeleniumSession$print_page`
## ------------------------------------------------
## Not run:
session <- SeleniumSession$new()
session$navigate("https://www.r-project.org")
session$print_page()
session$close()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.