| ShadowRoot | R Documentation |
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.
idThe 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_idThe id of the session.
req, verbosePrivate fields of a SeleniumSession object.
idThe 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
)usingThe type of selector to use.
valueThe value of the selector: a string.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
A WebElement object.
\dontrun{
session <- SeleniumSession$new()
# 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
)usingThe type of selector to use.
valueThe value of the selector: a string.
request_bodyA list of request body parameters to pass to the Selenium server, overriding the default body of the web request
timeoutHow long to wait for a request to receive a response before throwing an error.
A list of WebElement objects.
\dontrun{
session <- SeleniumSession$new()
# 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)
deepWhether 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.