python selenium 模块的安装及使用

安装

pip install selenium 或者到https://pypi.python.org/pypi/selenium 下载setup安装包,之后进入目录后运行python setup.py install

官方文档

官方文档地址:http://selenium-python.readthedocs.io/installation.html

安装驱动

需要下载相应浏览器的驱动,驱动下载地址:http://docs.seleniumhq.org/download/

把geckodriver.exe放置到Python的目录,也把驱动放到Firefox的安装目录,并把Firefox的路径添加到系统环境变量path

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


class PythonOrgSearch(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        assert "No results found." not in driver.page_source

    def tearDown(self):
        self.driver.close()


if __name__ == "__main__":
    unittest.main()

参考:

https://www.cnblogs.com/gopythoner/p/7735379.html
http://blog.csdn.net/nhudx061/article/details/43601065/
http://selenium-python.readthedocs.io/installation.html
https://www.cnblogs.com/fnng/p/3325300.html
http://www.51testing.com/zhuanti/selenium.html
http://blog.csdn.net/blueheart20/article/details/70768930
https://www.cnblogs.com/fnng/archive/2013/05/29/3106515.html
https://github.com/mozilla/geckodriver/releases
https://www.zhihu.com/question/49568096

转载于:https://www.cnblogs.com/Python666/p/7816653.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值