Python_Win7 x86下Selenium+Python+Eclipse配置

來源:互聯網
上載者:User

1. 首先配置eclipse+pydev環境
  a) 安裝jdk
  b) 安裝eclipse
 c)安裝Python2.7,安裝Pydev
2. 去官網(http://seleniumhq.org/download/)下載Selenium Python檔案
點擊python的Download ,進入selenium python的下載頁面,https://pypi.python.org/pypi/selenium 


3.下載Selenium-2.35.0.tar.gz,然後解壓進行安裝, 執行命令python setup.py install
或者在目錄C:\Python27\Scripts下執行命令:pip install -U selenium安裝selenium,不過需要先安裝setuptools-py27(https://pypi.python.org/pypi/setuptools/1.0)
4. ChromeDriverhttps://code.google.com/p/chromedriver/downloads/detail?name=chromedriver_win32_2.2.zip&can=2&q=,然後把chromedriver解壓到C:\Python27目錄下(chromedriver需要用最新的版本)

5 .執行測試指令碼:
 from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Chrome() # Get local session of firefox
browser.get("http://www.baidu.com") # Load page
assert "Yahoo!" in browser.title
elem = browser.find_element_by_name("p") # Find the query box
elem.send_keys("seleniumhq" + Keys.RETURN)
time.sleep(0.2) # Let the page load, will be added to the API
try:
    browser.find_element_by_xpath("//a[contains(@href,'http://seleniumhq.org')]")
except NoSuchElementException:
    assert 0, "can't find seleniumhq"
browser.close()

7.開啟IE失敗方法的解決
問題如下:(我使用的是Python)
WebDriverException: Message: u'Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones.'
後來查了好些資料,找到了兩種解決辦法:
1)修改IE的安全性原則,就像Exception裡面提示的那樣。
2)在產生webdriver對象之前先執行這些代碼:
1 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2 DesiredCapabilities.INTERNETEXPLORER['ignoreProtectedModeSettings'] = True

聯繫我們

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