RSelenium icon indicating copy to clipboard operation
RSelenium copied to clipboard

Unable to inherit from RSelenium classes

Open rgzn opened this issue 6 years ago • 1 comments

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)

rgzn avatar Dec 12 '18 22:12 rgzn

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?

rgzn avatar Dec 13 '18 00:12 rgzn