R/json.R

Defines functions parse_json_result prepare_for_json

prepare_for_json <- function(x) {
  if (inherits_any(x, c("WebElement", "ShadowRoot"))) {
    x$toJSON()
  } else if (is_bare_list(x)) {
    lapply(x, prepare_for_json)
  } else {
    x
  }
}

parse_json_result <- function(x, self) {
  if (rlang::is_bare_list(x) && length(x) == 1 && names(x) %in% c(web_element_id, shadow_element_id)) {
    if (names(x) == web_element_id) {
      self$create_webelement(x[[1]])
    } else {
      self$create_shadowroot(x[[1]])
    }
  } else if (rlang::is_bare_list(x)) {
    lapply(x, parse_json_result, self)
  } else {
    x
  }
}

Try the selenium package in your browser

Any scripts or data that you put into this service are public.

selenium documentation built on Sept. 30, 2024, 9:22 a.m.