Title: | Low-Level Browser Automation Interface |
---|---|
Description: | An implementation of 'W3C WebDriver 2.0' (<https://w3c.github.io/webdriver/>), allowing interaction with a 'Selenium Server' (<https://www.selenium.dev/documentation/grid/>) instance from 'R'. Allows a web browser to be automated from 'R'. |
Authors: | Ashby Thorpe [aut, cre, cph] |
Maintainer: | Ashby Thorpe <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.4.9000 |
Built: | 2024-10-23 06:00:51 UTC |
Source: | https://github.com/ashbythorpe/selenium-r |
Mouse actions to be passed into actions_stream()
. actions_mousedown()
represents pressing a button on the mouse, while actions_mouseup()
represents releasing a button. actions_mousemove()
represents moving the
mouse.
actions_mousedown( button = c("left", "right", "middle"), width = NULL, height = NULL, pressure = NULL, tangential_pressure = NULL, tilt_x = NULL, tilt_y = NULL, twist = NULL, altitude_angle = NULL, azimuth_angle = NULL ) actions_mouseup( button = c("left", "right", "middle"), width = NULL, height = NULL, pressure = NULL, tangential_pressure = NULL, tilt_x = NULL, tilt_y = NULL, twist = NULL, altitude_angle = NULL, azimuth_angle = NULL ) actions_mousemove( x, y, duration = NULL, origin = c("viewport", "pointer"), width = NULL, height = NULL, pressure = NULL, tangential_pressure = NULL, tilt_x = NULL, tilt_y = NULL, twist = NULL, altitude_angle = NULL, azimuth_angle = NULL )
actions_mousedown( button = c("left", "right", "middle"), width = NULL, height = NULL, pressure = NULL, tangential_pressure = NULL, tilt_x = NULL, tilt_y = NULL, twist = NULL, altitude_angle = NULL, azimuth_angle = NULL ) actions_mouseup( button = c("left", "right", "middle"), width = NULL, height = NULL, pressure = NULL, tangential_pressure = NULL, tilt_x = NULL, tilt_y = NULL, twist = NULL, altitude_angle = NULL, azimuth_angle = NULL ) actions_mousemove( x, y, duration = NULL, origin = c("viewport", "pointer"), width = NULL, height = NULL, pressure = NULL, tangential_pressure = NULL, tilt_x = NULL, tilt_y = NULL, twist = NULL, altitude_angle = NULL, azimuth_angle = NULL )
button |
The mouse button to press. |
width |
The 'width' of the click, a number. |
height |
The 'height' of the click, a number. |
pressure |
The amount of pressure to apply to the click: a number between 0 and 1. |
tangential_pressure |
A number between 0 and 1. |
tilt_x |
A whole number between -90 and 90. |
tilt_y |
A whole number between -90 and 90. |
twist |
A whole number between 0 and 359. |
altitude_angle |
A number between 0 and |
azimuth_angle |
A number between 0 and |
x |
The x coordinate of the mouse movement. |
y |
The y coordinate of the mouse movement. |
duration |
The duration of the mouse movement, in seconds. |
origin |
The point from which |
A selenium_action
object.
actions_stream( actions_mousedown("left", width = 1, height = 1, pressure = 0.5), actions_mouseup("left", width = 100, height = 50, pressure = 1), actions_mousemove(x = 1, y = 1, duration = 1, origin = "pointer") )
actions_stream( actions_mousedown("left", width = 1, height = 1, pressure = 0.5), actions_mouseup("left", width = 100, height = 50, pressure = 1), actions_mousemove(x = 1, y = 1, duration = 1, origin = "pointer") )
A pause action to be passed into actions_stream()
. Waits for a given
number of seconds before performing the next action in the stream.
actions_pause(seconds)
actions_pause(seconds)
seconds |
The number of seconds to wait for. |
A selenium_action
object.
actions_stream( actions_pause(1) )
actions_stream( actions_pause(1) )
Key actions to be passed into actions_stream()
. actions_press()
represents pressing a key on the keyboard, while actions_release()
represents releasing a key.
actions_press(key) actions_release(key)
actions_press(key) actions_release(key)
key |
The key to press: a string consisting of a single character. Use
the keys object to use special keys (e.g. |
A selenium_action
object.
actions_stream( actions_press("a"), actions_release("a"), actions_press(keys$enter), actions_release(keys$enter) )
actions_stream( actions_press("a"), actions_release("a"), actions_press(keys$enter), actions_release(keys$enter) )
Scroll actions to be passed into actions_stream()
. Scroll the page in
a given direction.
actions_scroll(x, y, delta_x, delta_y, duration = NULL, origin = "viewport")
actions_scroll(x, y, delta_x, delta_y, duration = NULL, origin = "viewport")
x |
The x coordinate from which the scroll action originates from. |
y |
The y coordinate from which the scroll action originates from. |
delta_x |
The number of pixels to scroll in the x direction. |
delta_y |
The number of pixels to scroll in the y direction. |
duration |
The duration of the scroll, in seconds. |
origin |
The point from which |
A selenium_action
object.
actions_stream( actions_scroll(x = 1, y = 1, delta_x = 1, delta_y = 1, duration = 0.5) )
actions_stream( actions_scroll(x = 1, y = 1, delta_x = 1, delta_y = 1, duration = 0.5) )
actions_stream()
creates a set of actions to be performed by
SeleniumSession$perform_actions()
. Actions are a low level way to interact
with a page.
actions_stream(...)
actions_stream(...)
... |
|
A selenium_actions_stream
object, ready to be passed into
SeleniumSession$perform_actions()
.
Pause actions: actions_pause()
.
Press actions: actions_press()
and actions_release()
.
Mouse actions: actions_mousedown()
, actions_mouseup()
and actions_mousemove()
.
Scroll actions: actions_scroll()
.
actions_stream( actions_press(keys$enter), actions_pause(0.5), actions_release(keys$enter), actions_scroll(x = 1, y = 1, delta_x = 1, delta_y = 1, duration = 0.5), actions_mousemove(x = 1, y = 1, duration = 1, origin = "pointer") )
actions_stream( actions_press(keys$enter), actions_pause(0.5), actions_release(keys$enter), actions_scroll(x = 1, y = 1, delta_x = 1, delta_y = 1, duration = 0.5), actions_mousemove(x = 1, y = 1, duration = 1, origin = "pointer") )
Create browser options to pass into the capabilities
argument of
SeleniumSession$new().
chrome_options( binary = NULL, args = NULL, extensions = NULL, prefs = NULL, ... ) firefox_options(binary = NULL, args = NULL, profile = NULL, prefs = NULL, ...) edge_options(binary = NULL, args = NULL, extensions = NULL, prefs = NULL, ...)
chrome_options( binary = NULL, args = NULL, extensions = NULL, prefs = NULL, ... ) firefox_options(binary = NULL, args = NULL, profile = NULL, prefs = NULL, ...) edge_options(binary = NULL, args = NULL, extensions = NULL, prefs = NULL, ...)
binary |
Path to the browser binary. |
args |
A character vector of additional arguments to pass to the browser. |
extensions |
A character vector of paths to browser extension ( |
prefs |
A named list of preferences to set in the browser. |
... |
Additional options to pass to the browser. |
profile |
Path to a Firefox profile directory. This will be base64 encoded before being passed to the browser. |
These functions allow you to more easily translate between Selenium code in other languages (e.g. Java/Python) to R. For example, consider the following Java code, adapted from the the Selenium documentation
ChromeOptions options = new ChromeOptions(); options.setBinary("/path/to/chrome"); options.addArguments("--headless", "--disable-gpu"); options.addExtensions("/path/to/extension.crx"); options.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));
This can be translated to R as follows:
chrome_options( binary = "/path/to/chrome", args = c("--headless", "--disable-gpu"), extensions = "/path/to/extension.crx", excludeSwitches = list("disable-popup-blocking") )
You can combine these options with non-browser specific options simply using
c()
.
Note that Microsoft Edge options are very similar to Chrome options, since it is based on Chromium.
A list of browser options, with Chrome options under the name
goog:chromeOptions
, Firefox options under moz:firefoxOptions
, and Edge
options under ms:edgeOptions
.
For more information and examples on Chrome options, see: https://developer.chrome.com/docs/chromedriver/capabilities
For Firefox options: https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions
For other options that affect Firefox but are not under mox:firefoxOptions
,
see:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Capabilities.html
For Edge options, see: https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/capabilities-edge-options#edgeoptions-object
# Basic options objects chrome_options( binary = "/path/to/chrome", args = c("--headless", "--disable-gpu"), detatch = TRUE, # An additional option described in the link above. prefs = list( "profile.default_content_setting_values.notifications" = 2 ) ) firefox_options(binary = "/path/to/firefox") edge_options(binary = "/path/to/edge") # Setting the user agent chrome_options(args = c("--user-agent=My User Agent")) edge_options(args = c("--user-agent=My User Agent")) firefox_options(prefs = list( "general.useragent.override" = "My User Agent" )) # Using a proxy server chrome_options(args = c("--proxy-server=HOST:PORT")) edge_options(args = c("--proxy-server=HOST:PORT")) PORT <- 1 firefox_options(prefs = list( "network.proxy.type" = 1, "network.proxy.socks" = "HOST", "network.proxy.socks_port" = PORT, "network.proxy.socks_remote_dns" = FALSE )) # Combining with other options browser_options <- chrome_options(binary = "/path/to/chrome") c(browser_options, list(platformName = "Windows"))
# Basic options objects chrome_options( binary = "/path/to/chrome", args = c("--headless", "--disable-gpu"), detatch = TRUE, # An additional option described in the link above. prefs = list( "profile.default_content_setting_values.notifications" = 2 ) ) firefox_options(binary = "/path/to/firefox") edge_options(binary = "/path/to/edge") # Setting the user agent chrome_options(args = c("--user-agent=My User Agent")) edge_options(args = c("--user-agent=My User Agent")) firefox_options(prefs = list( "general.useragent.override" = "My User Agent" )) # Using a proxy server chrome_options(args = c("--proxy-server=HOST:PORT")) edge_options(args = c("--proxy-server=HOST:PORT")) PORT <- 1 firefox_options(prefs = list( "network.proxy.type" = 1, "network.proxy.socks" = "HOST", "network.proxy.socks_port" = PORT, "network.proxy.socks_remote_dns" = FALSE )) # Combining with other options browser_options <- chrome_options(binary = "/path/to/chrome") c(browser_options, list(platformName = "Windows"))
When a chord of keys is passed into WebElement$send_keys()
, all keys will
be pressed in order, and then released at the end. This is simply done by
combining the keys into a single string, and appending the NULL key
(keys$null) to the end. This is useful for keybindings like
Ctrl-V
, where you want the Ctrl key to be released after the action.
key_chord(...)
key_chord(...)
... |
The keys to be combined (strings). |
A string.
# `Ctrl-V` will be pressed, then `Ctrl-Alt-V` paste0( keys$control, "v", keys$alt, "v" ) # `Ctrl-V` will be pressed, then `Alt-V` paste0( key_chord(keys$control, "v"), key_chord(keys$alt, "v") )
# `Ctrl-V` will be pressed, then `Ctrl-Alt-V` paste0( keys$control, "v", keys$alt, "v" ) # `Ctrl-V` will be pressed, then `Alt-V` paste0( key_chord(keys$control, "v"), key_chord(keys$alt, "v") )
A named list of special keys, where each key is a single Unicode character,
which will be interpreted by selenium as a special key. Each key is just a
string, so can be used with string manipulation functions like paste()
without any special treatment.
keys
keys
An object of class list
of length 65.
keys$enter
keys$enter
Downloads the latest release of Selenium Server, and then runs it as a background process. You must have Java installed for this command to work.
selenium_server( version = "latest", selenium_manager = TRUE, interactive = TRUE, verbose = TRUE, temp = TRUE, path = NULL, echo_cmd = FALSE, extra_args = c() )
selenium_server( version = "latest", selenium_manager = TRUE, interactive = TRUE, verbose = TRUE, temp = TRUE, path = NULL, echo_cmd = FALSE, extra_args = c() )
version |
The version of Selenium Server to download and run. By default, the latest major or minor release is used. |
selenium_manager |
Whether to enable Selenium Manager, which will
automatically download any missing drivers. Defaults to |
interactive |
By default, if you don't have a version downloaded, you
will be prompted to confirm that you want to download it, and the function
will error if |
verbose |
Passed into |
temp |
Whether to use a temporary directory to download the Selenium
Server |
path |
The path where the downloaded Selenium Server |
echo_cmd |
Passed into processx::process$new(). |
extra_args |
A character vector of extra arguments to pass into the Selenium Server call. See the list of options here: https://www.selenium.dev/documentation/grid/configuration/cli_options/ |
A processx::process object. Call <process>$kill()
to stop the
server.
The package website for more ways to start the Selenium server.
## Not run: # Disables the prompt that asks you whether you want to download Selenium server server <- selenium_server(interactive = FALSE) # Saves the server in your user data directory server <- selenium_server(temp = FALSE) server$kill() # The server doesn't have to be downloaded again server <- selenium_server(temp = FALSE) # Here we use extra arguments to increase the timeout of client sessions, # allowing sessions to stay open for longer without being automatically # terminated. server <- selenium_server(extra_args = c("--session-timeout", "3000")) ## End(Not run)
## Not run: # Disables the prompt that asks you whether you want to download Selenium server server <- selenium_server(interactive = FALSE) # Saves the server in your user data directory server <- selenium_server(temp = FALSE) server$kill() # The server doesn't have to be downloaded again server <- selenium_server(temp = FALSE) # Here we use extra arguments to increase the timeout of client sessions, # allowing sessions to stay open for longer without being automatically # terminated. server <- selenium_server(extra_args = c("--session-timeout", "3000")) ## End(Not run)
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.
id
The id of the session, generated when the session is started.
browser
The browser that the session is using.
port
The port that the session is using.
host
The 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 )
browser
The name of the browser to use (e.g. "chrome", "firefox", "edge").
port
The port that the Selenium server is using, so we can connect to it.
host
The host that the Selenium server is running on. This is usually 'localhost' (i.e. your own machine).
verbose
Whether to print the web requests that are being sent and any responses.
capabilities
A 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_body
A list of request body parameters to pass to the
Selenium server. Overrides capabilities
.
timeout
How long to wait for a request to recieve 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)
id
The 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)
id
The 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)
timeout
How long to wait for a request to recieve a response before throwing an error.
The session object, invisibly.
\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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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 )
script
The amount of time to wait for scripts. By default, this is not set.
page_load
The amount of time to wait for the page to load.
implicit_wait
The amount of time to wait for elements on the page.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
url
The URL to navigate to. Must begin with a protocol (e.g. 'https://').
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request.
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
handle
The handle of the window to switch to.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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 )
type
Whether to create a tab or a window.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
id
The 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_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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 )
width
The width of the window.
height
The height of the window.
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.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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 )
using
The type of selector to use.
value
The value of the selector: a string.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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 )
using
The type of selector to use.
value
The value of the selector: a string.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
x
The 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_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
x
The 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_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
name
The name of the cookie.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
cookie
The cookie object to add: a list which must contain a
name
and value
field.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
name
The name of the cookie.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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 )
actions
A selenium_actions_stream
object, created using
actions_stream()
.
release_actions
Whether to call release_actions()
after
performing the actions.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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)
text
The text to send.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
timeout
How long to wait for a request to recieve 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 )
orientation
The page orientation, either "portrait"
or
"landscape"
.
scale
The page scale, a number between 0.1 and 2.
background
Whether to print the background of the page.
width
The page width, in inches.
height
The page height, in inches.
margin
The 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.
footer
The page footer, as a string.
header
The page header, as a string.
shrink_to_fit
Whether to shrink the page to fit the width and height.
page_ranges
A list of page ranges (e.g. "1"
, "1-3"
) to print.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve 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)
deep
Whether 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)
## ------------------------------------------------ ## 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)
A shadow DOM is a self-contained DOM tree, contained within another DOM tree. A shadow root is an element that contains a DOM subtree. This class represents a shadow root object, allowing you to select elements within the shadow root.
id
The id of the shadow root.
new()
Initialize a new ShadowRoot
object. This should not be called
manually: instead use WebElement$shadow_root(), or
SeleniumSession$create_shadow_root().
ShadowRoot$new(session_id, req, verbose, id)
session_id
The id of the session.
req, verbose
Private fields of a SeleniumSession object.
id
The id of the shadow root.
A ShadowRoot
object.
\dontrun{ session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") element$shadow_root() session$close() }
find_element()
Find an element in the shadow root.
ShadowRoot$find_element( using = c("css selector", "xpath", "tag name", "link text", "partial link text"), value, request_body = NULL, timeout = 20 )
using
The type of selector to use.
value
The value of the selector: a string.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
A WebElement object.
\dontrun{ session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); const shadowRoot = div.attachShadow({mode: 'open'}); const span = document.createElement('span'); span.textContent = 'Hello'; shadowRoot.appendChild(span); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() shadow_root$find_element(using = "css selector", value = "span") session$close() }
find_elements()
Find all elements in a shadow root matching a selector.
ShadowRoot$find_elements( using = c("css selector", "xpath", "tag name", "link text", "partial link text"), value, request_body = NULL, timeout = 20 )
using
The type of selector to use.
value
The value of the selector: a string.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
A list of WebElement objects.
\dontrun{ session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); const shadowRoot = div.attachShadow({mode: 'open'}); const span = document.createElement('span'); span.textContent = 'Hello'; shadowRoot.appendChild(span); const p = document.createElement('p'); p.textContent = 'Me too!'; shadowRoot.appendChild(p); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() shadow_root$find_elements(using = "css selector", value = "*") session$close() }
toJSON()
Convert an element to JSON. This is used by SeleniumSession$execute_script().
ShadowRoot$toJSON()
A list, which can then be converted to JSON using
jsonlite::toJSON()
.
\dontrun{ session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() result <- shadow_root$toJSON() result jsonlite::toJSON(result, auto_unbox = TRUE) session$close() }
clone()
The objects of this class are cloneable with this method.
ShadowRoot$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `ShadowRoot$new` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") element$shadow_root() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `ShadowRoot$find_element` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); const shadowRoot = div.attachShadow({mode: 'open'}); const span = document.createElement('span'); span.textContent = 'Hello'; shadowRoot.appendChild(span); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() shadow_root$find_element(using = "css selector", value = "span") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `ShadowRoot$find_elements` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); const shadowRoot = div.attachShadow({mode: 'open'}); const span = document.createElement('span'); span.textContent = 'Hello'; shadowRoot.appendChild(span); const p = document.createElement('p'); p.textContent = 'Me too!'; shadowRoot.appendChild(p); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() shadow_root$find_elements(using = "css selector", value = "*") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `ShadowRoot$toJSON` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() result <- shadow_root$toJSON() result jsonlite::toJSON(result, auto_unbox = TRUE) session$close() ## End(Not run)
## ------------------------------------------------ ## Method `ShadowRoot$new` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") element$shadow_root() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `ShadowRoot$find_element` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); const shadowRoot = div.attachShadow({mode: 'open'}); const span = document.createElement('span'); span.textContent = 'Hello'; shadowRoot.appendChild(span); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() shadow_root$find_element(using = "css selector", value = "span") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `ShadowRoot$find_elements` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); const shadowRoot = div.attachShadow({mode: 'open'}); const span = document.createElement('span'); span.textContent = 'Hello'; shadowRoot.appendChild(span); const p = document.createElement('p'); p.textContent = 'Me too!'; shadowRoot.appendChild(p); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() shadow_root$find_elements(using = "css selector", value = "*") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `ShadowRoot$toJSON` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() result <- shadow_root$toJSON() result jsonlite::toJSON(result, auto_unbox = TRUE) session$close() ## End(Not run)
wait_for_server()
takes a server process returned by selenium_server()
and waits for it to respond to status requests. If it doesn't, then an
error is thrown detailing any errors in the response and any error messages
from the server.
selenium_server_available()
returns TRUE
if a Selenium server is
running on a given port and host. wait_for_selenium_available()
waits
for the Selenium server to become available for a given time, throwing an
error if one does not. It is similar to wait_for_server()
except that it
works with servers not created by selenium.
get_server_status()
, when given a port and host, figures out whether a
Selenium server instance is running, and if so, returns its status. This is
used by selenium_server_available()
to figure out if the server is
running.
wait_for_server( server, port = 4444L, host = "localhost", max_time = 60, error = TRUE, verbose = FALSE, timeout = 20 ) selenium_server_available( port = 4444L, host = "localhost", verbose = FALSE, timeout = 20 ) wait_for_selenium_available( max_time = 60, port = 4444L, host = "localhost", error = TRUE, verbose = FALSE, timeout = 20 ) get_server_status( port = 4444L, host = "localhost", verbose = FALSE, timeout = 20 )
wait_for_server( server, port = 4444L, host = "localhost", max_time = 60, error = TRUE, verbose = FALSE, timeout = 20 ) selenium_server_available( port = 4444L, host = "localhost", verbose = FALSE, timeout = 20 ) wait_for_selenium_available( max_time = 60, port = 4444L, host = "localhost", error = TRUE, verbose = FALSE, timeout = 20 ) get_server_status( port = 4444L, host = "localhost", verbose = FALSE, timeout = 20 )
server |
The process object returned by |
port |
The port that the Selenium server is using, so we can connect to it. |
host |
The host that the Selenium server is running on. This is usually 'localhost' (i.e. Your own machine). |
max_time |
The amount of time to wait for the Selenium server to become available. |
error |
Whether to throw an error if the web request fails
after the timeout is exceeded. If not, and we can't connect to a server,
|
verbose |
Whether to print information about the web request that is sent. |
timeout |
How long to wait for a request to recieve a response before throwing an error. |
wait_for_server()
and wait_for_selenium_available()
return TRUE
if
the server is ready to be connected to, and throw an error otherwise.
selenium_server_available()
returns TRUE
if a Selenium server is
running, and FALSE
otherwise.
get_server_status()
returns 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.
## Not run: server <- selenium_server() wait_for_server(server) get_server_status() selenium_server_available() wait_for_selenium_available() ## End(Not run)
## Not run: server <- selenium_server() wait_for_server(server) get_server_status() selenium_server_available() wait_for_selenium_available() ## End(Not run)
This class represents a single element on the page. It is created using an existing SeleniumSession instance.
id
The id of the element, used to uniquely identify it on the page.
new()
Initialize a WebElement
object. This should not be called manually:
instead use SeleniumSession$create_webelement() if
you have an element id. To find elements on the page, use
SeleniumSession$find_element() and
SeleniumSession$find_elements().
WebElement$new(session_id, req, verbose, id)
session_id
The id of the session that the element belongs to.
req, verbose
Private fields of a SeleniumSession object.
id
The element id.
A WebElement
object.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") element <- session$find_element(using = "css selector", value = "#download") session$close() }
shadow_root()
A shadow DOM is a self-contained DOM tree, contained within another DOM tree. A shadow root is an element that contains a DOM subtree. This method gets the shadow root property of an element.
WebElement$shadow_root(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
A ShadowRoot object.
\dontrun{ session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() session$close() }
find_element()
Find the first element matching a selector, relative to the current element.
WebElement$find_element( using = c("css selector", "xpath", "tag name", "link text", "partial link text"), value, request_body = NULL, timeout = 20 )
using
The type of selector to use.
value
The value of the selector: a string.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
A WebElement
object.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") row <- session$find_element(using = "css selector", value = ".row") logo_container <- row$find_element(using = "css selector", value = "p") logo <- logo_container$find_element(using = "css selector", value = "img") session$close() }
find_elements()
Find all elements matching a selector, relative to the current element.
WebElement$find_elements( using = c("css selector", "xpath", "tag name", "link text", "partial link text"), value, request_body = NULL, timeout = 20 )
using
The type of selector to use.
value
The value of the selector: a string.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
A list of WebElement
objects.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") row <- session$find_element(using = "css selector", value = ".row") links <- row$find_elements(using = "css selector", value = "a") session$close() }
is_selected()
Check if an element is currently selected.
WebElement$is_selected(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
A boolean value: TRUE
or FALSE
.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$is_selected() session$close() }
get_attribute()
Get an attribute from an element.
WebElement$get_attribute(name, request_body = NULL, timeout = 20)
name
The name of the attribute.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
The value of the attribute: a string.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_attribute("href") session$close() }
get_property()
Get a property from an element. Properties are similar to attributes, but represent the HTML source code of the page, rather than the current state of the DOM.
WebElement$get_property(name, request_body = NULL, timeout = 20)
name
The name of the property.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
The value of the property: a string.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_property("href") session$close() }
get_css_value()
Get the computed value of a CSS property.
WebElement$get_css_value(name, request_body = NULL, timeout = 20)
name
The name of the CSS property.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
The value of the CSS property: a string.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_css_value("color") session$close() }
get_text()
Get the text content of an element.
WebElement$get_text(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
The text content of the element: a string.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_text() session$close() }
get_tag_name()
Get the tag name of an element.
WebElement$get_tag_name(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
The tag name of the element: a string.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_tag_name() session$close() }
get_rect()
Get the dimensions and coordinates of an element.
WebElement$get_rect(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
A list containing the following elements:
x
: The x-coordinate of the element.
y
: The y-coordinate of the element.
width
: The width of the element in pixels.
height
: The height of the element in pixels.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_rect() session$close() }
is_enabled()
Check if an element is currently enabled.
WebElement$is_enabled(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
A boolean value: TRUE
or FALSE
.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$is_enabled() session$close() }
computed_role()
Get the computed role of an element. The role of an element is usually "generic", but is often used when an elements tag name differs from its purpose. For example, a link that is "button-like" in nature may have a "button" role.
WebElement$computed_role(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
A string.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$computed_role() session$close() }
computed_label()
Get the computed label of an element (i.e. The text of the label element that points to the current element).
WebElement$computed_label(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
A string.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$computed_label() session$close() }
click()
Click on an element.
WebElement$click(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
The element, invisibly.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$click() session$close() }
clear()
Clear the contents of a text input element.
WebElement$clear(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
The element, invisibly.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.google.com") session$find_element(using = "css selector", value = "textarea")$clear() session$close() }
send_keys()
Send keys to an element.
WebElement$send_keys(..., request_body = NULL, timeout = 20)
...
The keys to send (strings). Use keys for special keys, and
use key_chord()
to send keys combinations.
request_body
A list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeout
How long to wait for a request to recieve a response before throwing an error.
The element, invisibly.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.google.com") input <- session$find_element(using = "css selector", value = "textarea") input$send_keys("Hello") input$send_keys(key_chord(keys$control, "a"), key_chord(keys$control, "c")) input$send_keys(keys$control, "v") input$get_attribute("value") session$close() }
screenshot()
Take a screenshot of an element.
WebElement$screenshot(timeout = 20)
timeout
How long to wait for a request to recieve 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$find_element(using = "css selector", value = "a")$screenshot() session$close() }
is_displayed()
Check if an element is displayed. This function may not work on all platforms.
WebElement$is_displayed(timeout = 20)
timeout
How long to wait for a request to recieve a response before throwing an error.
A boolean.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$is_displayed() session$close() }
toJSON()
Convert an element to JSON. This is used by SeleniumSession$execute_script().
WebElement$toJSON()
A list, which can then be converted to JSON using
jsonlite::toJSON()
.
\dontrun{ session <- SeleniumSession$new() session$navigate("https://www.r-project.org") result <- session$find_element(using = "css selector", value = "a")$toJSON() result jsonlite::toJSON(result, auto_unbox = TRUE) session$close() }
clone()
The objects of this class are cloneable with this method.
WebElement$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------ ## Method `WebElement$new` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") element <- session$find_element(using = "css selector", value = "#download") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$shadow_root` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$find_element` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") row <- session$find_element(using = "css selector", value = ".row") logo_container <- row$find_element(using = "css selector", value = "p") logo <- logo_container$find_element(using = "css selector", value = "img") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$find_elements` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") row <- session$find_element(using = "css selector", value = ".row") links <- row$find_elements(using = "css selector", value = "a") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$is_selected` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$is_selected() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_attribute` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_attribute("href") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_property` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_property("href") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_css_value` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_css_value("color") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_text` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_text() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_tag_name` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_tag_name() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_rect` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_rect() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$is_enabled` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$is_enabled() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$computed_role` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$computed_role() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$computed_label` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$computed_label() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$click` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$click() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$clear` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.google.com") session$find_element(using = "css selector", value = "textarea")$clear() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$send_keys` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.google.com") input <- session$find_element(using = "css selector", value = "textarea") input$send_keys("Hello") input$send_keys(key_chord(keys$control, "a"), key_chord(keys$control, "c")) input$send_keys(keys$control, "v") input$get_attribute("value") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$screenshot` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$screenshot() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$is_displayed` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$is_displayed() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$toJSON` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") result <- session$find_element(using = "css selector", value = "a")$toJSON() result jsonlite::toJSON(result, auto_unbox = TRUE) session$close() ## End(Not run)
## ------------------------------------------------ ## Method `WebElement$new` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") element <- session$find_element(using = "css selector", value = "#download") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$shadow_root` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() # Let's create our own Shadow Root using JavaScript session$execute_script(" const div = document.createElement('div'); document.body.appendChild(div); div.attachShadow({mode: 'open'}); ") element <- session$find_element(using = "css selector", value = "div") shadow_root <- element$shadow_root() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$find_element` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") row <- session$find_element(using = "css selector", value = ".row") logo_container <- row$find_element(using = "css selector", value = "p") logo <- logo_container$find_element(using = "css selector", value = "img") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$find_elements` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") row <- session$find_element(using = "css selector", value = ".row") links <- row$find_elements(using = "css selector", value = "a") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$is_selected` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$is_selected() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_attribute` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_attribute("href") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_property` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_property("href") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_css_value` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$get_css_value("color") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_text` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_text() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_tag_name` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_tag_name() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$get_rect` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "#download")$get_rect() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$is_enabled` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$is_enabled() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$computed_role` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$computed_role() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$computed_label` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$computed_label() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$click` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$click() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$clear` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.google.com") session$find_element(using = "css selector", value = "textarea")$clear() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$send_keys` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.google.com") input <- session$find_element(using = "css selector", value = "textarea") input$send_keys("Hello") input$send_keys(key_chord(keys$control, "a"), key_chord(keys$control, "c")) input$send_keys(keys$control, "v") input$get_attribute("value") session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$screenshot` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$screenshot() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$is_displayed` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") session$find_element(using = "css selector", value = "a")$is_displayed() session$close() ## End(Not run) ## ------------------------------------------------ ## Method `WebElement$toJSON` ## ------------------------------------------------ ## Not run: session <- SeleniumSession$new() session$navigate("https://www.r-project.org") result <- session$find_element(using = "css selector", value = "a")$toJSON() result jsonlite::toJSON(result, auto_unbox = TRUE) session$close() ## End(Not run)