简体   繁体   English

RSelenium java.lang.IllegalStateException

[英]RSelenium java.lang.IllegalStateException

I am trying to open a remote driver using the RSelenium package with Chrome driver and encountering the following error: 我正在尝试使用带有Chrome驱动程序的RSelenium软件包打开远程驱动程序,并遇到以下错误:

Error:   Summary: UnknownError
Detail: An unknown server-side error occurred while processing the command.
class: java.lang.IllegalStateException

This question has been asked previous on stackoverflow, but the solution (which I tried in full) did not work. 之前在stackoverflow上已经提出过这个问题,但是解决方案 (我完全尝试过)不起作用。 I also consulted this and this . 我也咨询了这个这个

My basic code in R is as follows. 我在R中的基本代码如下。 The error occurs after the following line remDr$open() . 在以下行remDr$open()之后发生错误。

install.packages("RSelenium")
library(RSelenium)

checkForServer()              
startServer()
Sys.sleep(5.0)
remDr <- remoteDriver( browserName="chrome" )            
remDr$open() 

Specs: 眼镜:

  • R: v.3.3.0 R:v.3.3.0
  • Working in R with RStudio v.0.99.902 使用RStudio v.0.99.902在R中工作
  • OS: OSX El Capital 10.11.3 操作系统:OSX El Capital 10.11.3
  • Java: 1.8.92.14 Java:1.8.92.14
  • I also downloaded the chrome driver v2.21 here . 我还在这里下载了chrome驱动程序v2.21。 It's currently living in its own folder within Applications. 它目前位于Applications中的自己的文件夹中。

To fix this problem I have tried: 为了解决这个问题,我尝试过:

  1. Two alternative versions of the startServer() command below. 下面是startServer()命令的两个替代版本。 The first threw the same error, the second also told me No Selenium Server binary exists. Run checkForServer or start server manually. 第一个抛出相同的错误,第二个也告诉我No Selenium Server binary exists. Run checkForServer or start server manually. No Selenium Server binary exists. Run checkForServer or start server manually.
    • startServer(args = c("-Dwebdriver.chrome.driver=/mypath/to/chromedriver.exe") , log = FALSE, invisible = FALSE)
    • and startServer(dir = FALSE, args = c("-Dwebdriver.chrome.driver=/mypath/to/chromedriver.exe") , log = FALSE, invisible = FALSE) startServer(dir = FALSE, args = c("-Dwebdriver.chrome.driver=/mypath/to/chromedriver.exe") , log = FALSE, invisible = FALSE)
  2. Running the following in the terminal (and leaving the terminal open while running the R code): java -jar /mypath/to/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/mypath/to/chromedriver.exe . 在终端中运行以下命令(并在运行R代码时打开终端): java -jar /mypath/to/selenium-server-standalone.jar -Dwebdriver.chrome.driver=/mypath/to/chromedriver.exe This threw the same error. 这引起了同样的错误。
  3. Creating a .command file that contains the information I previously entered into the terminal above (2) and calling that file within R as below. 创建一个.command文件,其中包含我先前在上面的终端(2)中输入的信息,并在R中调用该文件,如下所示。

.

install.packages("RSelenium")
library(RSelenium)
system(paste("open","/mypath/command.command")
remDr <- remoteDriver( browserName="chrome" )            
remDr$open()  

This resulted in the following error The file could not be executed because you do not have appropriate access privileges. 这导致以下错误The file could not be executed because you do not have appropriate access privileges. Navigating to the .command file in Finder and changing all of the Sharing & Permissions to Read & Write did not change the error message. 导航到Finder中的.command文件并将所有共享和权限更改为读取和写入不会更改错误消息。

  1. Reinstalling all components - Chrome Driver, Selenium .jar file, package RSelenium . 重新安装所有组件 - Chrome驱动程序,Selenium .jar文件,包RSelenium Restarting R. Updating R and RStudio. 重新启动R.更新R和RStudio。

  2. Using a default remote driver (Firefox, I believe) like this remDr <- remoteDriver$new() . 使用默认的远程驱动程序(我相信,Firefox)就像这个remDr <- remoteDriver$new() Different error: class: org.openqa.selenium.WebDriverException . 不同的错误: class: org.openqa.selenium.WebDriverException

  3. Updating Firefox to help with 5 above to no avail. 更新Firefox以帮助5以上无济于事。

Help would be appreciated. 帮助将不胜感激。

Breaking the rules here asking for clarification. 在这里打破规则要求澄清。 But this problem is driving my crazy. 但是这个问题让我发疯了。 Could you list the versions of everything you used when you got it working. 你能列出你工作时使用的所有版本吗?

For me: 为了我:

R 3.3.0 GUI 1.68 Mavericks build R 3.3.0 GUI 1.68 Mavericks build

RStudio Version 0.99.902 RStudio版本0.99.902

OSX El Capital 10.11.5 OSX El Capital 10.11.5

Java: 1.8.0_91 Java:1.8.0_91

selenium-server-standalone-2.53.1.jar 硒的服务器独立,2.53.1.jar

FF 47.0 (and also tried FF 46.0) FF 47.0(也尝试了FF 46.0)

still lead to org.openqa.selenium.firefox.NotConnectedException 仍导致org.openqa.selenium.firefox.NotConnectedException

The following solved the problem: 以下解决了这个问题:

checkForServer()              
startServer( args = c( "-port 4455" ), log = FALSE, invisible = FALSE )
remDr <- remoteDriver( browserName="firefox", port=4455 )            
remDr$open( silent=T ) 

I am not sure why it worked (and perhaps someone can answer that), but this did the trick. 我不确定它为什么会起作用(也许有人可以回答),但这就是诀窍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM