RSelenium UnknownError - java.lang.IllegalStateException with Google Chrome

前端 未结 2 1941
心在旅途
心在旅途 2020-12-10 00:20

I am running the following script based on the RSelenium Basics CRAN page:

library(RSelenium)
startServer(args = c(\"-port 4455\"), log = FALSE, invisible =          


        
相关标签:
2条回答
  • 2020-12-10 00:44

    I was finally able to get RSelenium to work by piecing together information from a number of different sources. I think it would be helpful to have all of this information in one location, so here is the process that I went through to get RSelenium to work on Windows 7 (64-bit) with Chrome as the browser:

    1. Download the 64-bit version of Java. I could not get anything to work with the standard download.
    2. Download ChromeDriver.
    3. Download the Selenium Standalone Server or run checkForServer() from R.
    4. Create a batch file to start the Selenium server. I initially tried to use startServer() from an R script, but it would frequently get stuck and not carry on to the next line in the script. Here is the batch file that I created:

      java -jar C:\path\to\selenium-server-standalone.jar -Dwebdriver.chrome.driver=C:\path\to\chromedriver.exe
      

      ChromeDriver can be put in the PATH environmental variable, but I decided to add in the path to ChromeDriver to the batch file (which accomplishes the same goal).

    5. Run the R script. Here is my final script:

      library(RSelenium)
      shell.exec(paste0("C:\\path\\to\\yourbatchfile.bat"))
      Sys.sleep(5)
      
      remDr <- remoteDriver(browserName = "chrome")
      remDr$open(silent = TRUE)
      remDr$navigate("http://www.google.com")
      

      The Sys.sleep() call was necessary because I would get an error in the remoteDriver() call if it ran before the Selenium Server had finished starting.

    0 讨论(0)
  • 2020-12-10 00:47

    It is worth noting that RSelenium has some annoying differences for OSX. The invisible=T/silent=T arguments will not work when you run the yourcommand.command file and the remDr$open() method, respectively. The invisible=T will actually remind you that it only works on Windows. Not a huge deal (and if someone has a workaround I'd appreciate it).

    For posterity's sake here's a slight variation for OSX to replace shell.exec using a .command file instead of a .bat with the same contents as above:

    yourcommand.command file contents

    java -jar /path/to/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/path/to/chromedriver
    

    R script modification

    library(RSelenium)
    system(paste("open","/path/to/yourcommand.command"))
    Sys.sleep(5)
    ...
    
    0 讨论(0)
提交回复
热议问题