zoukankan      html  css  js  c++  java
  • selenium安装环境

    selenium自动化环境:selenium+python+chromedriver 驱动/ ie驱动/火狐驱动
    1.selenium和python安装
     
    cmd命令里输入:pip install selenium
    或者具体的版本: cmd输入指令安装selenium:pip install selenium==2.53.6
    selenium类似于客户端,通过浏览器驱动器 等浏览器驱动连接客户端
    2下载浏览器驱动

    前面说过,selenium支持多种浏览器,所以只需要下载对应的浏览器驱动,将解压得到的exe文件放到python的安装目录下即可;

    各个浏览器驱动下载地址(较慢不推荐):http://www.seleniumhq.org/download/

    驱动下载地址:
    Chrome驱动器下载: https://sites.google.com/a/chromium.org/chromedriver/downloads
    放到chrome的安装目录下...GoogleChromeApplication ,然后设置path环境变量
    Edge驱动器下载: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
    Firefox驱动器下载: https://github.com/mozilla/geckodriver/releases
    放到chrome的安装目录下Firefox所在的安装路径,我的是"E:Mozilla Firefox",设置path环境变量
    Path:E:Mozilla Firefox;
    Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/

    ie驱动器下载:http://www.pc6.com/softview/SoftView_435420.html

    验证selenium

     1.确保电脑上安装了Firefox浏览器

     2.cmd窗口输入如下指令

      python

      from selenium import webdriver

      webdriver.Firefox()

    webdriver.Chrome()

    webdriver.Ie()

     3.如果能启动浏览器,说明环境安装OK。

    注意:若用Firefox浏览器,只能用46及46以下的版本(selenium2不兼容47以上)

     selenium IDE安装

    http://blog.csdn.net/echizen_520/article/details/65444396

    若用Ie或Chrome浏览器,需要先下载浏览器驱动,将驱动文件放到python根目录(D:Python27)

           

            配置驱动环境变量(path)

    查看驱动浏览器实例:

    #coding=utf-8
    from selenium import webdriver
    import unittest
    class VisitGGByIE(unittest.TestCase):
        def setUp(self):# unittest包的方法前面小写+后面单词Up首字母大写
            #启动ie浏览器
            self.driver=webdriver.Ie(executable_path="D:\Python27\chromedriver")#注意后面不加.exe
        def test_visitGG(self):
            #访问搜索首页
            self.driver.get("https://97gg.net")
            #打印当前网页的网址
            print self.driver.current_url
            #退出ie浏览器
        def tearDown(self):
            self.driver.quit()
            #pass

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

    selenium IDE安装 http://blog.csdn.net/echizen_520/article/details/65444396
  • 相关阅读:
    使用sudo crontab修改Linux系统时间
    Redis缓存雪崩和穿透的解决方法
    设计模式之委托模式
    设计模式之模板模式
    并发编程面试题
    AQS之共享锁实现原理
    AQS之独占锁实现原理
    CentOS 7.1 Bridge启用STP报错"Master connection not found or invalid"
    nginx反向代理docker registry报”blob upload unknown"解决办法
    [转]Linux df 命令不更新磁盘数据空间使用情况的解决办法
  • 原文地址:https://www.cnblogs.com/zyy98877/p/8573968.html
Copyright © 2011-2022 走看看