Selenium+Python的環境配置

來源:互聯網
上載者:User

標籤:gecko   安裝完成   使用   attribute   selenium   http   .com   ref   nload   

因為項目的原因,最近較多的使用了UFT來進行自動化測試工作,半年沒有使用Selenium了,於是在自己的電腦上重新設定了基於python3.x的selenium環境,配置過程大致如下:

1. Selenium安裝

Selenium在python下的環境配置相對簡單,只需在python中安裝selenium的包即可。

2. Webdriver安裝

但對於針對不同瀏覽器的webdriver還需單獨安裝。

之前在使用python2時,並沒有對firefox瀏覽器安裝單獨的driver,但這次發現對於firefox,同樣需要安裝第三方驅動:geckodriver

否則報錯為:

selenium.common.exceptions.WebDriverException: Message: ‘geckodriver‘ executable needs to be in PATH. 

Exception AttributeError: "‘Service‘ object has no attribute ‘process‘"

下載驅動(http://docs.seleniumhq.org/download/)後,將該驅動解壓,並放置在firefox的目錄下,隨後將該路徑添加至系統內容變數path,重啟python環境,即可完成webdriver安裝

3. 其他瀏覽器

對於ChromeDriver,安裝過程大致類似,不再贅述

 

安裝完成後,可以簡單地使用以下代碼來測試安裝效果:

1 from selenium import webdriver2 3 driver = webdriver.Firefox()4 driver.get(“http://www.cnblogs.com/persistz/") #URL

 

Selenium+Python的環境配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.