Reputation: 347
I am using Rselenium and today I got a weird issue. It was working until last friday but now it got crashed. I have updated main packages and also java but it is not working. This is what I get when I use next code:
library(wdman)
library(RSelenium)
library(xml2)
library(selectr)
library(httr)
library(jsonlite)
#start RSelenium
remDr <- rsDriver(
port = 4445L,
browser = "firefox"
)
#remDr$open()
remDr <- remoteDriver(port = 4445L,browser = "firefox")
When running the first remDr for rsDriver I got this:
checking Selenium Server versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking geckodriver versions:
BEGIN: PREDOWNLOAD
Error in (function (url, platform, history, appname, platformregex = platform, :
unused argument (fileregex = "\\.(gz|zip)$")
And for the second remDr, it works but trying to use open it fails and shows next message:
remDr$open()
[1] "Connecting to remote server"
Error in checkError(res) :
Undefined error in httr call. httr output: Failed to connect to localhost port 4445: Connection refused
How can I solve these issues? This is the session info:
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] jsonlite_1.8.4 httr_1.4.4 selectr_0.4-2 xml2_1.3.3 RSelenium_1.7.9
[6] wdman_0.2.6
loaded via a namespace (and not attached):
[1] Rcpp_1.0.9 binman_0.1.2 assertthat_0.2.1 rappdirs_0.3.3 bitops_1.0-7
[6] R6_2.5.1 semver_0.2.0 magrittr_2.0.3 stringi_1.7.6 curl_4.3.2
[11] tools_4.1.2 stringr_1.4.0 yaml_2.3.5 compiler_4.1.2 caTools_1.18.2
Upvotes: 6
Views: 1135
Reputation: 438
Since this issue re-occurrs every time there is a driver upgrade I have the following code to automatically fix it. Note that you will need to modify the directory where your driver is (second last line). You can keep this at the top of your RSelenium script and run it before the session kicks off.
library(wdman)
out_ret_command <- selenium(retcommand=T)
ver_to_unlink <- gsub("[^0-9.-]", "",gsub(".*win32(.+)LICENSE.chromedriver.*", "\\1", out_ret_command))
unlink_str <- paste("C:/Users/User/AppData/Local/binman/binman_chromedriver/win32/",ver_to_unlink,"/LICENSE.chromedriver", sep = "")
unlink(unlink_str)
Upvotes: 0
Reputation: 2940
SOLUTION: DELETE the LICENSE.chromedriver
file.
You can find the file location which is printed in the output of:
library(wdman)
selenium(retcommand=T)
#delete the LICENSE.chromedriver file
To DELETE the file: On linux terminal:(you may need to change the version)
sudo rm -rf /myusername/.local/share/binman_chromedriver/linux64/110.0.5481.30/LICENSE.chromedriver
Note: you must be using the apt version rather than snap if using linux: https://www.omgubuntu.co.uk/2022/04/how-to-install-firefox-deb-apt-ubuntu-22-04
To DELETE the file: On mac terminal:(you may need to change the version)
sudo rm /Users/myusername/Library/Application Support/binman_chromedriver/mac64/110.0.5481.30/LICENSE.chromedriver
To DELETE the file: In windows R console:(you may need to change the version)
#replace WINDOWSUSERNAME with your windows username and chromedriver version
port <- 4444L
unlink("C:/Users/WINDOWSUSERNAME/AppData/Local/binman/binman_chromedriver/win32/110.0.5481.30/LICENSE.chromedriver")
library(RSelenium)
rd <- rsDriver(port=as.integer(port),browser="firefox")
###if you still get Selenium server signals port = 4444 is already in use.
you can reset the port using the below command in windows:
#clear busy port in windows
port <- 4444L
tintern <- system("netstat -a -n -o",intern=T)
irow1 <- grep(as.character(port),tintern)
if(length(irow1)>0){
irow1 <- irow1[1]
if(!is.na(irow1)){
irow1 <- irow1[1]
trow <- tintern[irow1]
trow <- trimws(rm_white(trow))
tpid <- word(trow,-1,-1)
system(paste0("taskkill /pid ",tpid," /F"))
}
}
Upvotes: 7
Reputation: 21
On my macOS 10.14.6 the problem was an old java version. With
rd <- rsDriver(browser = "firefox",chromever = NULL)
I got this failure:
Could not open firefox browser. Client error message: Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Connection refused
rd$server$log()
$stderr
[1] "Exception in thread \"main\" java.lang.UnsupportedClassVersionError: org/openqa/grid/selenium/GridLauncherV3 : Unsupported major.minor version 52.0"
[2] "\tat java.lang.ClassLoader.defineClass1(Native Method)"
[3] "\tat java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)"
...
After updating java to JDK 17 the problems were gone.
See also the answer from Jeff Parker here.
Update: Due to the error message "Could not open firefox browser", I had also to reinstall the RSelenium package and remove the old geckodrivers in this way:
remove.packages("RSelenium")
delete the directory ~/Library/Application Support/binman_geckodriver
install.packages("RSelenium")
cDrv3<- rsDriver(port = 4444L,browser = "firefox",chromever = NULL)
remDr <- cDrv3[["client"]]
During the first rsDriver()
call, the correct geckodrivers are automatically installed from RSelenium.
Upvotes: 0
Reputation: 1
I would like to highlight that deleting the file LICENSE.chromedriver
solves the second issue
Error in checkError(res) :
Undefined error in httr call. httr output: Failed to connect to localhost port 4445: Connection refused
The first issue
Error in (function (url, platform, history, appname, platformregex = platform, :
unused argument (fileregex = "\\.(gz|zip)$")
arises after updating wdman
package from 0.2.5 to 0.2.6. I had to revert back to 0.2.5 to solve this.
Upvotes: -1