R/windows.R

Defines functions move_to_element focus_last_window focus_first_window switchToWindow get_handles

Documented in focus_first_window focus_last_window

get_handles <- function() {
  get_browser()$getWindowHandles() %>% unlist()
}

# https://github.com/ropensci/RSelenium/issues/143
switchToWindow <- function(remDr, windowId) {
  qpath <- sprintf(
    "%s/session/%s/window", remDr$serverURL,
    remDr$sessionInfo[["id"]]
  )
  remDr$queryRD(qpath, "POST", qdata = list(handle = windowId))
}

#' @rdname ele_action
#' @export
focus_first_window <- function(p = get_browser()) {
  # TODO: fix here
  handles <- get_handles()
  switchToWindow(p, first(handles))
  # p$switchToWindow(first(handles))
}

#' @rdname ele_action
#' @export
focus_last_window <- function(p = get_browser()) {
  handles <- get_handles()
  switchToWindow(p, last(handles))
  # p$switchToWindow(last(handles))
}

# https://github.com/ropensci/RSelenium/issues/254
#' @export
move_to_element <- function(x, dx = NA_integer_, dy = NA_integer_) {
  remDr <- get_browser()
  remDr$mouseMoveToLocation(dx, dy, webElement = x)
  # remDr$executeScript("arguments[0].scrollIntoView(true);", list(x))
  invisible()
  x
}
rpkgs/curlR documentation built on Jan. 30, 2023, 7:26 p.m.