【Selenium系列】 1. Selenium 环境搭建
OS:Windows 8.1 64-bit
编程语言:Python 3.4 64-bit
1. 安装Python
2. 安装Setuptools
3. 安装pip
4. 安装selenium
pip install selenium
5. 测试 selenium 可用
c:\>python Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import selenium >>> quit() c:\>
编写一个Python程序, start_selenium_demo.py , 通过 selenium 打开firefox,转到百度首页 https://www.baidu.com/ :
# -*- coding:utf-8 -*- from selenium import webdriver from selenium.common.exceptions import NoSuchElementException import time browser = webdriver.Firefox() if __name__ == "__main__": browser.get(r'https://www.baidu.com/') assert '百度一下,你就知道' in browser.title try: elem = browser.find_element_by_xpath(".//*[@id='kw']") elem.send_keys('selenum python') except NoSuchElementException: assert 0, "can't find element keyword input widget" browser.close()
参考:
1. http://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html
2.

浙公网安备 33010602011771号