mirror of https://git.sr.ht/~hrbrmstr/htmlunit
boB Rudis
5 years ago
6 changed files with 155 additions and 12 deletions
@ -0,0 +1,43 @@ |
|||
#' Click on a DOM element in a webclient loaded page |
|||
#' |
|||
#' @note The caller does not have to assign the output of this function to a |
|||
#' variable as the browser state is managed internally by HtmlUnit. |
|||
#' @param wc_obj a `webclient` object |
|||
#' @param css,xpath Node to click on. Supply one of css or xpath depending on whether you want to use a css or xpath 1.0 selector. |
|||
#' @export |
|||
wc_click_on <- function(wc_obj, css, xpath) { |
|||
|
|||
pg <- wc_obj$wc$getCurrentWindow()$getEnclosedPage() |
|||
|
|||
if (.jnull() == pg) return(NULL) |
|||
|
|||
if (missing(css) && missing(xpath)) |
|||
stop("Please supply one of css or xpath", call. = FALSE) |
|||
|
|||
if (!missing(css) && !missing(xpath)) |
|||
stop("Please supply css or xpath, not both", call. = FALSE) |
|||
|
|||
if (!missing(css)) { |
|||
if (!is.character(css) && length(css) == 1) stop("`css` must be a string") |
|||
|
|||
item <- pg$querySelector(css) |
|||
|
|||
} else { |
|||
if (!is.character(xpath) && length(xpath) == 1) |
|||
stop("`xpath` must be a string") |
|||
|
|||
item <- as.list(pg$getByXPath(xpath))[[1]] |
|||
|
|||
} |
|||
|
|||
if (length(item) == 0) { |
|||
warning("No item found with that selector.") |
|||
} else if (length(item) > 1) { |
|||
warning("More than one item found with that selector.") |
|||
} else { |
|||
item$click() |
|||
} |
|||
|
|||
return(wc_obj) |
|||
|
|||
} |
@ -1,17 +1,43 @@ |
|||
#' Retrieve a form on a webclient page by name |
|||
#' Fill in a input box in a form field |
|||
#' |
|||
#' @note This returns a `webclient_form` object _not_ the `wc_obj` passed in |
|||
#' @note The caller does not have to assign the output of this function to a |
|||
#' variable as the browser state is managed internally by HtmlUnit. |
|||
#' @param wc_obj a `webclient` object |
|||
#' @param name form name |
|||
#' @param css,xpath Node to select. Supply one of css or xpath depending on whether you want to use a css or xpath 1.0 selector. |
|||
#' @export |
|||
wc_get_form_by_name <- function(wc_obj, name) { |
|||
wc_fill_in <- function(wc_obj, value, css, xpath) { |
|||
|
|||
pg <- wc_obj$wc$getCurrentWindow()$getEnclosedPage() |
|||
|
|||
if (.jnull() == pg) return(NULL) |
|||
|
|||
f <- pg$getFormByName(name) |
|||
if (missing(css) && missing(xpath)) |
|||
stop("Please supply one of css or xpath", call. = FALSE) |
|||
|
|||
f |
|||
if (!missing(css) && !missing(xpath)) |
|||
stop("Please supply css or xpath, not both", call. = FALSE) |
|||
|
|||
if (!missing(css)) { |
|||
if (!is.character(css) && length(css) == 1) stop("`css` must be a string") |
|||
|
|||
item <- pg$querySelector(css) |
|||
|
|||
} else { |
|||
if (!is.character(xpath) && length(xpath) == 1) |
|||
stop("`xpath` must be a string") |
|||
|
|||
item <- as.list(pg$getByXPath(xpath))[[1]] |
|||
|
|||
} |
|||
|
|||
if (length(item) == 0) { |
|||
warning("No item found with that selector.") |
|||
} else if (length(item) > 1) { |
|||
warning("More than one item found with that selector.") |
|||
} else { |
|||
|
|||
} |
|||
|
|||
return(wc_obj) |
|||
|
|||
} |
|||
|
@ -0,0 +1,20 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/wc-click.R |
|||
\name{wc_click_on} |
|||
\alias{wc_click_on} |
|||
\title{Click on a DOM element in a webclient loaded page} |
|||
\usage{ |
|||
wc_click_on(wc_obj, css, xpath) |
|||
} |
|||
\arguments{ |
|||
\item{wc_obj}{a \code{webclient} object} |
|||
|
|||
\item{css, xpath}{Node to click on. Supply one of css or xpath depending on whether you want to use a css or xpath 1.0 selector.} |
|||
} |
|||
\description{ |
|||
Click on a DOM element in a webclient loaded page |
|||
} |
|||
\note{ |
|||
The caller does not have to assign the output of this function to a |
|||
variable as the browser state is managed internally by HtmlUnit. |
|||
} |
@ -0,0 +1,20 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/wc-forms.R |
|||
\name{wc_fill_in} |
|||
\alias{wc_fill_in} |
|||
\title{Fill in a input box in a form field} |
|||
\usage{ |
|||
wc_fill_in(wc_obj, value, css, xpath) |
|||
} |
|||
\arguments{ |
|||
\item{wc_obj}{a \code{webclient} object} |
|||
|
|||
\item{css, xpath}{Node to select. Supply one of css or xpath depending on whether you want to use a css or xpath 1.0 selector.} |
|||
} |
|||
\description{ |
|||
Fill in a input box in a form field |
|||
} |
|||
\note{ |
|||
The caller does not have to assign the output of this function to a |
|||
variable as the browser state is managed internally by HtmlUnit. |
|||
} |
Loading…
Reference in new issue