Selenium之浏览器驱动下载和配置使用

发表于:2023-4-10 09:28

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:biao666    来源:博客园

  1、安装selenium
  pip install selenium
  2、浏览器驱动下载
  2.1 下载地址
  根据自己的操作系统下载相对应的驱动:
  (1)Chrome浏览器驱动(chromedriver ):http://chromedriver.storage.googleapis.com/index.html
  (2)Firefox浏览器驱动(geckodriver):https://github.com/mozilla/geckodriver/releases/
  (3)Edge浏览器驱动(MicrosoftWebDriver):https://github.com/mozilla/geckodriver/releases/
  (4)IE浏览器驱动(IEDriverServer):http://selenium-release.storage.googleapis.com/index.html
  (5)Opera浏览器驱动(operadriver):https://github.com/operasoftware/operachromiumdriver/releases
  (6)PhantomJS浏览器驱动(phantomjs):https://github.com/operasoftware/operachromiumdriver/releases
  2.2 使用
   把文件存放在python根目录下,例如:C:\xxx\Python\Python38下。
  3、使用测试
  验证浏览器驱动是否正常使用, 前提python环境正常, selenium包已经安装(pip install selenium)
  创建.py文件输入以下内容运行验证:
  # 导包
  from selenium import webdriver
  from time import sleep
  # 创建浏览器驱动对象, 以下为创建不同浏览器驱动对象
  driver = webdriver.Chrome()    # Chrome浏览器
  # driver = webdriver.Firefox()   # Firefox浏览器
  # driver = webdriver.Edge()      # Edge浏览器
  # driver = webdriver.Ie()        # Internet Explorer浏览器
  # driver = webdriver.Opera()     # Opera浏览器
  # driver = webdriver.PhantomJS()   # PhantomJS
  # 打开指定网址
  driver.get('https://www.baidu.com')
  # 休眠3秒
  sleep(3)
  # 关闭浏览器驱动对象
  driver.quit()
  本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号