Python_Win7 x86下Selenium+Python+Eclipse配置

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 

Python_Win7 x86下Selenium+Python+Eclipse配置_第1张图片
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. ChromeDriver下载地址https://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

你可能感兴趣的:(Python_Win7 x86下Selenium+Python+Eclipse配置)