安装 selenium
python 中:安装 selenium 第三方模块。你可以查看已安装的模块信息:
C:\tmp>pip show selenium
Name: selenium
Version: 3.12.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: c:\python\python36-32\lib\site-packages
Requires:
Required-by:
如果没有这些信息显示,需要使用 pip 命令安装:
打开cmd对话框输入下面的安装语句,前提是已经装了python和pip
pip install selenium
编写第一个自动化脚本
安装了 selenium 之后,我们就可以开始编写自动化脚本了。使用程序员必备工具 UltraEdit,来编写你的第一个自动
化脚本。
#coding=utf-8
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("http://www.baidu.com")
driver.find_element_by_id("kw").send_keys("Selenium2")
driver.find_element_by_id("su").click