## ------------------------------------------------
## Method `ShadowRoot$new`
## ------------------------------------------------
if (FALSE) {
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()
}
## ------------------------------------------------
## Method `ShadowRoot$find_element`
## ------------------------------------------------
if (FALSE) {
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()
}
## ------------------------------------------------
## Method `ShadowRoot$find_elements`
## ------------------------------------------------
if (FALSE) {
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()
}
## ------------------------------------------------
## Method `ShadowRoot$toJSON`
## ------------------------------------------------
if (FALSE) {
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()
}
Run the code above in your browser using DataLab