RSelenium
RSelenium copied to clipboard
Unable to inherit from RSelenium classes
If you try to inherit from one of the exported RSelenium classes, such as remoteDriver or webElement, you get an error when trying to initialize the object.
Error in callSuper(...) : object 'statCodes' not found
statCodes is a data.frame held in sysdata.R, which is not accessible to the R environment that loaded the package. statCodes is not exported into the RSelenium namespace.
Here is a small example of trying to inherit from RSelenium::remoteDriver:
require(wdman)
require(RSelenium)
loadNamespace("RSelenium")
customScraper <- setRefClass(
Class = "customScraper",
fields = list(
username = "character",
password = "character",
home_url = "character",
download_path = "character"
),
contains = "remoteDriver",
methods = list(
initialize =
function(
username = "username",
password = "password",
home_url = "https://awebsite.com",
download_path = getwd(),
...
) {
username <<- username
password <<- password
if ( Sys.info()['sysname'] == "Windows" ) {
download_path <<- gsub("/", "\\\\", download_path)
} else {
download_path <<- download_path
}
callSuper(...)
}
)
)
chromeDriver <- chrome()
myScraper <- customScraper()
This fails unless I add the following hack to get the statCodes data.frame:
myErrorHandler = RSelenium::errorHandler$new()
statCodes = myErrorHandler$statusCodes
rm(myErrorHandler)
I guess there are further problems with inheritance in reference classes.
For example, calling remoteDriver methods like findElement() from the child class above will generate an error.
Perhaps RSelenium should convert to R6 classes?