Issue
I am working with the R programming language.
My Problem: I have the following R Selenium script that used to work before (August 2023) but now does not work (November 2023):
library(RSelenium)
library(wdman)
library(netstat)
selenium()
# checking Selenium Server versions:
#BEGIN: PREDOWNLOAD
#BEGIN: DOWNLOAD
#BEGIN: POSTDOWNLOAD
#....
#BEGIN: DOWNLOAD
#BEGIN: POSTDOWNLOAD
#$process
#PROCESS 'file27547a8c5781.bat', running, pid 14124.
binman::list_versions("chromedriver")
#$win32
#[1] "113.0.5672.63" "114.0.5735.16" "114.0.5735.90"
seleium_object <- selenium(retcommand = T, check = F)
remote_driver <- rsDriver(browser = "chrome", chromever = "119.0.6045.105", verbose = F, port = free_port())
However, this results in the following error:
Error in chrome_ver(chromecheck[["platform"]], chromever) :
version requested doesnt match versions available = 113.0.5672.63,114.0.5735.16,114.0.5735.90
My Question: In a previous question (R: Is it possible to download the latest version of Google Chrome directly in R?), I was told I might be able to solve this problem by using Chromium (https://www.chromium.org/getting-involved/download-chromium/) instead of Google Chrome. But I have never used Chromium before - I am not sure how to install it and how to modify the rest of my script so that it works with Chromium:
# rest of R/selenium script (currently does not work)
#remDr = remote_driver
#remDr$navigate("https://www.google.com/maps")
# Search for the CN Tower
#search_box <- remDr$findElement(using = 'css selector', "#searchboxinput")
#search_box$sendKeysToElement(list("CN Tower", key = "enter"))
#Sys.sleep(5)
# Get the URL of the current page
#url <- remDr$getCurrentUrl()[[1]]
# Extract the longitude and latitude from the URL
#long_lat <- gsub(".*@(-?[0-9.]+),(-?[0-9.]+),.*", "\\1,\\2", url)
#long_lat <- unlist(strsplit(long_lat, ","))
Can someone please show me how to correctly install chromium (e.g. can this be done directly with an R command (e.g. System() or shell.exec() ) and how to modify the rest of my R selenium script such that it works with Chromium?
Thanks!
> sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
[5] LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] netstat_0.1.2 wdman_0.2.6 RSelenium_1.7.9 duckdb_0.7.1-1 DBI_1.1.3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8.3 rstudioapi_0.13 xml2_1.3.3 knitr_1.39 rappdirs_0.3.3 R6_2.5.1 rlang_1.0.6
[8] fastmap_1.1.0 httr_1.4.4 caTools_1.18.2 tools_4.1.3 xfun_0.30 binman_0.1.3 tinytex_0.45
[15] KernSmooth_2.23-20 cli_3.4.1 e1071_1.7-9 semver_0.2.0 htmltools_0.5.3 class_7.3-20 yaml_2.3.5
[22] digest_0.6.29 assertthat_0.2.1 processx_3.8.0 ps_1.7.2 bitops_1.0-7 curl_4.3.2 evaluate_0.19
[29] rmarkdown_2.14 proxy_0.4-26 compiler_4.1.3 classInt_0.4-3 jsonlite_1.8.4
Solution
I was able to solve this problem (with a friend).
First, I went on the Google Chrome Driver website: https://chromedriver.chromium.org/downloads -> https://googlechromelabs.github.io/chrome-for-testing/
Then, I downloaded the files for the driver I wanted (On Nov 23 2023, I downloaded the most recent available version,
ChromeDriver 114.0.5735.90
)Then, I unzipped the contents of this file and made a new folder with the name of the driver (I called the folder
119.0.6045.160
.... this is the same as the current version of Google Chrome I am currently using:119.0.6045.160
)note: the name of the driver I downloaded DID NOT match the version of google chrome I am currently using
Then, I pasted the contents of this newly created folder into the following folder:
C:\Users\me\AppData\Local\binman\binman_chromedriver\win32
Finally, I ran the following code and everything worked!
library(RSelenium)
library(wdman)
library(netstat)
selenium()
seleium_object <- selenium(retcommand = T, check = F)
# chromever has the same name as the file I downloaded
remote_driver <- rsDriver(browser = "chrome", chromever = "119.0.6045.160", verbose = F, port = free_port())
remDr<- remote_driver$client
lat <- 45.5048
lon <- -73.5772
URL <- paste0("https://www.google.com/maps/search/pizza/@", lat, ",", lon, ",17z/data=!3m1!4b1!4m6!2m5!3m4!2s", lat, ",", lon, "!4m2!1d", lon, "!2d", lat, "?entry=ttu")
remDr$navigate(URL)
Answered By - stats_noob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.