Rselenium Unknownerror - Java.Lang.Illegalstateexception with Google Chrome

RSelenium UnknownError - java.lang.IllegalStateException with Google Chrome

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.

How to open Google Chrome with RSelenium?

Even though Google Chrome is installed, there is still something missing that is needed by Selenium. This is the "chromedriver". "chromedriver" can be downloaded on this website. Currently, the most recent version is 2.25. For instance, if one is using Windows, the file "chromedriver_win32.zip" needs to be downloaded.

When the file is downloaded, extract the file in it, i.e. "chromedriver.exe". Place "chromedriver.exe" where you want it to be. I put it in "User/Documents/R".

In the last step, you need to add the folder where "chromedriver.exe" is located to the system path. A description for adding a folder to the system path can be found here.

Now, one can restart R and run the code.

Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

Try to download HERE and use this latest chrome driver version:

  • https://sites.google.com/chromium.org/driver/

Try this:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')

Java Selenium Chromedriver.exe Does not Exist IllegalStateException

You have to give your chromeDriver.exe file path instead of taking the path from the URL.

example:

 System.setProperty("webdriver.chrome.driver",
"C:\\Downloads\\chromedriver.exe");


Related Topics



Leave a reply



Submit