RSelenium UnknownError - 使用谷歌浏览器的java.lang.IllegalStateException [英] RSelenium UnknownError - java.lang.IllegalStateException with Google Chrome
问题描述
我根据 RSelenium运行以下脚本基础知识CRAN页面:
library(RSelenium)
startServer(args = c("-port 4455"), log = FALSE, invisible = FALSE)
remDr <- remoteDriver(browserName = "chrome")
remDr$open()
这会产生以下错误:
Exception in thread "main" java.net.BindException: Selenium is already running on port 4444. Or some other service is.
at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:492)
at org.openqa.selenium.server.SeleniumServer.boot(SeleniumServer.java:305)
at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:245)
at org.openqa.grid.selenium.GridLauncher.main(GridLauncher.java:64)
根据在GitHub上的这个对话,我修改了我的 startServer()
命令,如下所示:
Based on the comments from this conversation on GitHub, I've modified my startServer()
command like so:
startServer(args = c("-port 4455"), log = FALSE, invisible = FALSE)
然后我在我的控制台中收到以下错误:
I then receive the following error in my console:
Error: Summary: UnknownError
Detail: An unknown server-side error occurred while processing the command.
class: java.lang.IllegalStateException
弹出的Java提示中出现此错误:
And this error in the Java prompt that pops up:
14:38:55.098 INFO - Launching a standalone Selenium Server
14:38:55:161 INFO - Java: Oracle Corporation 25.40-b25
14:38:55.161 INFO - OS: Windows 7 6.1 amd64
14:38:55.161 INFO - v2.46.0, with Core v2.46.0. Built from revision 87c69e2
14:38:55.209 INFO - Driver class not found: com.opera.core.systems.OperaDriver
14:38:55.209 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
14:38:55:289 INFO - RemoteWebDriver instances should connect to: http://127.0.0.1:4455/wd/hub
14:38:55:289 INFO - Selenium Server is up and running
我不确定缺少Opera驱动程序是否是实际错误或只是一个警告。无论如何,我想使用Chrome,所以看起来应该没关系。我做错了什么?
I'm not sure if the lack of an Opera driver is an actual error or just a warning. Regardless, I would like to use Chrome, so it seems like it shouldn't matter. What am I doing wrong?
推荐答案
我终于能够通过拼接来自多个不同来源的信息来使RSelenium工作。我认为将所有这些信息放在一个位置会很有帮助,所以这是我使用Chrome浏览器作为浏览器让RSelenium在Windows 7(64位)上运行的过程:
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:
- 下载 64位版本的Java 。我无法使用标准下载。
- 下载 ChromeDriver 。
- 下载 Selenium Standalone Server 或从R运行
checkForServer()
-
创建批处理文件以启动Selenium服务器。我最初尝试使用R脚本中的
startServer()
,但它会经常卡住而不是继续脚本中的下一行。这是我创建的批处理文件:
- Download the 64-bit version of Java. I could not get anything to work with the standard download.
- Download ChromeDriver.
- Download the Selenium Standalone Server or run
checkForServer()
from R. 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可以放在PATH环境变量中,但我决定在ChromeDriver的路径中添加批处理文件(实现相同的目标)。
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).
运行R脚本。这是我的最终脚本:
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")
Sys.sleep()
调用是必要的,因为我会收到错误如果它在Selenium Server完成启动之前运行,则在 remoteDriver()
调用。
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.
这篇关于RSelenium UnknownError - 使用谷歌浏览器的java.lang.IllegalStateException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!