我的下載代碼停止工作,因爲我的代碼停止正確傳遞「extraCapabilities」。RSelenium將配置文件/ extraCapabilities傳遞給服務器
這是用來工作:
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()
現在,它拋出一個錯誤:
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
我曾嘗試一種替代方案:
rD <- rsDriver(port = 4444L, browser = "firefox", version = "latest", geckover = "0.15.0", iedrver = NULL, phantomver = "2.1.1",
verbose = TRUE, check = TRUE, extraCapabilities = fprof)
產生同樣的錯誤除了投訴(這些投訴本身不會導致錯誤):
Selenium message:wrong number of arguments
如果extraCapabilities被刪除,上面的代碼執行,但如果你再試試:
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()
你的最後一行後得到同樣的錯誤。 rsDriver打開瀏覽器,但該瀏覽器沒有任何所需的屬性。如果您在嘗試分配remDr並打開它之前關閉瀏覽器(而不關閉服務器),您仍然會得到相同的錯誤。
我已經嘗試過版本13,14和15的驅動程序和Server 3.1.0,結果相同。
我發現了Java中引發錯誤的行,但我無法弄清楚如何傳遞不同於在後臺自動生成的Firefox配置文件。我已經嘗試過各種版本的「Profile」/「requiredProfile」/「FirefoxProfile」等等,但是沒有被認可爲有效的輸入......我也看到了一些關於如何在Java中完成的討論,在R.
代碼用於工作,直到大約36小時前,我一直在努力尋找出路。我現在處於完全喪失狀態。
更新:對組合版本非常敏感的設置。全新的Selenium服務器版本(3.3.1)可與Gecko 0.15.0和Firefox 52配合使用。其他一些組合可能有效,但大多數組合可能無效。
此外,設置文件夾位置字符串時,您需要小心。在R中的大多數情況下,正斜槓/
與操作系統無關,因此我大部分時間都在UNIX和Windows中使用它。但是,在Windows中設置browser.download.dir
時,顯然必須使用(轉義)反斜槓\\
。否則,目錄分配似乎可以正常工作,但事實上並不奏效。
最後,推薦的方法rsDriver
起作用,並且具有失效功能的方法也會再次起作用(checkForServer()
和startServer
)。需要學習的經驗:不要像我一樣運氣不好,以便更新Selenium代碼
看起來像硒的問題https://github.com/SeleniumHQ/selenium/issues/3632和https://github.com/SeleniumHQ/selenium/issues/3633 – jdharrison
給[[splashr]](https://github.com/hrbrmstr/splashr)試一試 – hrbrmstr
我已通讀介紹頁面包。很難看到我將如何使用此工具來實現文件下載。你有特定的工作流程嗎? –