python+selenium Remote 啟動firefox報錯總結

來源:互聯網
上載者:User

標籤:成功   提示   command   key   變數   .com   pre   查看   imp   

#coding=utf-8from selenium.webdriver import Remotedr = Remote(command_executor=‘http://127.0.0.1:4444/wd/hub‘,            desired_capabilities={‘platform‘:‘ANY‘,                                ‘browserName‘:‘firefox‘,                                ‘version‘:‘‘,                                ‘javascriptEnabled‘:True                                }            )dr.get("https://www.baidu.com")dr.find_element_by_id("kw").send_keys("grid")dr.find_element_by_id("su").click()print("ok")dr.quit()

這一段代碼一直報錯,也不知道原因,網上查看各種方法驗證之後都不行,改來改去,最後我也不知道那種方法改好的,只能把所有遇到問題記錄下來。報錯當時也沒有,只能回憶列一下大概的報錯資訊:

1、第一次排查,發現瀏覽器的安裝路徑沒有放到環境變數中,更正後,報錯

2、有網友的解決辦法是:開啟ie-設定-internet選項-區域網路lan設定-Proxy 伺服器。這一項不勾選。這個位置我的ie本來也沒勾選。所以此解決方案不行

3、錯誤提示:The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/ge... The latest version can be downloaded fromhttps://github.com/mozilla/ge...

下載之後將geckodriver解壓放在安裝目錄,加入path環境變數後運行依然報錯

4、error [10061]的報錯。忘記運行selenium server了

5、運行時瀏覽器被重複開啟多次報錯,

解決方案是:代碼中添加‘marionette’:False    運行成功。

 

以上就是我遇到的問題,具體的報錯資訊記不清楚了,大概記一下,也算是做個教訓。

以後遇到報錯,直接,問題解決後整理歸檔。

 

鬱悶的是:問題解決了,我卻不知道到底是那種方法解決的。

 

總結:

python+selenium 使用Remote啟動瀏覽器:

1、先啟動selenium server

2、更改代碼如下

#coding=utf-8from selenium.webdriver import Remotedr = Remote(command_executor=‘http://127.0.0.1:4444/wd/hub‘,            desired_capabilities={‘platform‘:‘ANY‘,                                ‘browserName‘:‘firefox‘,                                ‘version‘:‘‘,                                ‘javascriptEnabled‘:True,                                ‘marionette‘:False                                 }            )dr.get("https://www.baidu.com")dr.find_element_by_id("kw").send_keys("grid")dr.find_element_by_id("su").click()print("ok")dr.quit()

‘marionette’:False    marionette是python用戶端允許運行遠端控制基於gecko的瀏覽器或裝置運行一個marionette伺服器,包括案頭firefox和firefox os。該參數為firefox特用。

上述關於marionette解釋,參考於蟲師selenium2自動化測試的書,在p242

 

python+selenium Remote 啟動firefox報錯總結

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.