Reputation: 280
My download code stopped working as my code stopped passing "extraCapabilities" properly.
This is what used to work:
require(RSelenium)
require(XML)
require(data.table)
source(file.path(find.package("RSelenium"), "examples/serverUtils/checkForServer.r"))
source(file.path(find.package("RSelenium"), "examples/serverUtils/startServer.r"))
checkForServer();
server<-startServer()
referencedirectory <- "d://temp"
fprof <- makeFirefoxProfile(list(browser.download.dir = referencedirectory, browser.download.folderList = 2L, browser.download.manager.showWhenStarting = FALSE,
browser.helperApps.neverAsk.saveToDisk="text/xml",browser.tabs.remote.autostart = FALSE,browser.tabs.remote.autostart.2 = FALSE,browser.tabs.remote.desktopbehavior = FALSE))
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4444, browserName = "firefox",extraCapabilities = fprof)
remDr$open()
Now it throws an error:
Selenium message:Profile has been set on both the capabilities and these options, but they're different. Unable to determine which one you want to use.
Error: Summary: UnknownError
Detail: An unknown server-side error occurred while processing the command.
class: java.lang.IllegalStateException
Further Details: run errorDetails method
I have tried an alternative:
rD <- rsDriver(port = 4444L, browser = "firefox", version = "latest", geckover = "0.15.0", iedrver = NULL, phantomver = "2.1.1",
verbose = TRUE, check = TRUE, extraCapabilities = fprof)
That produces the same error in addition to complaining (these complaints do not result in an error by themselves):
Selenium message:wrong number of arguments
If extraCapabilities are removed, the above code executes, but if you then try:
rD <- rsDriver(port = 4446L, browser = "firefox", version = "latest", geckover = "0.15.0", iedrver = NULL, phantomver = "2.1.1",
verbose = TRUE, check = TRUE)
remDr <- rD[["client"]]
fprof <- makeFirefoxProfile(list(browser.download.dir = "D:/temp"))
remDr <- remoteDriver(extraCapabilities = fprof)
remDr$open()
You get the same error after the last line. rsDriver opens a browser, but that browser does not have any of the desired properties. If you close the browser (without closing the server) before trying to assign remDr and open it, you will still get the same error.
I have tried version 13, 14, and 15 of the driver and the Server 3.1.0, with the same result.
I have found the line in Java that is throwing the error, but I cannot figure out how to pass a different Firefox profile than the one that gets automatically generated behind the scenes. I have tried various versions of "Profile"/"requiredProfile"/"FirefoxProfile ", etc., but that does not get recognized as a valid input... I also see some discussion of how it may be done in Java, but not in R.
The code used to work for me until about 36 hours ago, and I have been trying to find the way out of it ever since. I am now at complete loss.
UPDATE: the setup with very sensitive about combination of versions. The brand new Selenium server version (3.3.1) works with Gecko 0.15.0 and Firefox 52. Some other combinations may work, but most do not.
Also, when setting the folder location string you need to be careful. In most contexts within R, the forward slash, /
is OS-neutral, as such, I use it most of the time both in UNIX and Windows. However, when setting browser.download.dir
in Windows, one apparently has to use the (escaped) backslash, \\
. Otherwise the directory assignment will appear to work, but it does not work de facto.
Finally, the recommended approach with rsDriver
works AND the approach with the defunct functions also works again (checkForServer()
and startServer
). Lesson to be learned: do not be unlucky like me in choosing the moment to update your Selenium code
Upvotes: 1
Views: 2618
Reputation: 51
it seems that you don't really need to makefireprof. the code is indeed very simple:
remDr=rsDriver(browser=browserName,extraCapabilities=list(acceptInsecureCerts=TRUE,acceptUntrustedCerts=TRUE))
Upvotes: 1
Reputation: 30425
It appears to be an issue with geckodriver(0.15.0)/selenium(3.3.0). I used the following:
library(RSelenium)
referencedirectory <- "c://temp"
fprof <- makeFirefoxProfile(list(browser.download.dir = referencedirectory, browser.download.folderList = 2L, browser.download.manager.showWhenStarting = FALSE,
browser.helperApps.neverAsk.saveToDisk="text/xml",browser.tabs.remote.autostart = FALSE,browser.tabs.remote.autostart.2 = FALSE,browser.tabs.remote.desktopbehavior = FALSE))
rD <- rsDriver(port = 4444L, browser = "firefox", version = "3.1.0", geckover = "0.14.0", iedrver = NULL, phantomver = "2.1.1",
verbose = TRUE, check = TRUE, extraCapabilities = fprof)
which appeared to function correctly. As noted in the documentation I would advise if possible to use a Docker image to run a Selenium Server which will prevent issues with incompatible browser/driver versions.
Update:
There is an updated version of selenium server which should now address this issue:
rD <- rsDriver(port = 4444L, browser = "firefox", version = "3.3.1", geckover = "0.15.0",
verbose = TRUE, check = TRUE, extraCapabilities = fprof)
Upvotes: 1