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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.