2017-03-10 32 views
1

我的下載代碼停止工作,因爲我的代碼停止正確傳遞「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代碼

+0

看起來像硒的問題https://github.com/SeleniumHQ/selenium/issues/3632和https://github.com/SeleniumHQ/selenium/issues/3633 – jdharrison

+0

給[[splashr]](https://github.com/hrbrmstr/splashr)試一試 – hrbrmstr

+0

我已通讀介紹頁面包。很難看到我將如何使用此工具來實現文件下載。你有特定的工作流程嗎? –

回答

0

這似乎是geckodriver(0.15.0)/ selenium(3.3.0)的問題。我使用以下內容:

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) 

它似乎正常工作。正如在文檔中指出的,我會建議如果可能的話使用Docker鏡像來運行Selenium服務器,這將防止瀏覽器/驅動程序版本不兼容的問題。

更新:

有硒服務器的更新版本,現在應該解決這個問題:

rD <- rsDriver(port = 4444L, browser = "firefox", version = "3.3.1", geckover = "0.15.0", 
       verbose = TRUE, check = TRUE, extraCapabilities = fprof) 
+0

我已複製並粘貼您的代碼。得到了和以前一樣的錯誤。我不能使用Docker安裝程序,因爲我不使用Windows 10.我嘗試過Toolbox(我認爲它被調用),並且安裝不成功。嘗試使用它時發生錯誤(在一臺PC上啓動服務器,甚至在另一臺PC上安裝)。我在 –

+0

的BIOS中激活了虛擬化是的firefox已更新。我正在運行以前的版本。將有一個Selenium服務器版本3.3.1 https://github.com/SeleniumHQ/selenium/releases/tag/selenium-3.3.1它應該解決即將發佈的問題。 – jdharrison

+0

當調用rsDriver時,是否可能影響服務器的「'moz:profile」中放入的內容? –

相關問題