(二)Python+ Selenium自动化测试入门打开三大浏览器

Firefox浏览器

  • 把firefox浏览器的安装目录拷贝到python安装目录下。
  • 最新版的firefox浏览器需要下载驱动,geckodriver,下载好之后把geckodriver复制到python安装目录下。
    下载地址:https://github.com/mozilla/geckodriver/releases/

Google 浏览器

  • 把Google浏览器的安装目录拷贝到python安装目录下。
  • 最新版的firefox浏览器需要下载驱动chromedriver,下载好之后把chromedriver复制到python安装目录下。
    下载地址:https://code.google.com/p/chromedriver/downloads/list

Internet Explore 浏览器

  • 同样的,IE浏览器需要也下载驱动IEdriver。
    下载地址:http://www.nuget.org/packages/Selenium.WebDriver.IEDriver/

注意:下载解压后,将chromedriver.exe , geckodriver.exe , Iedriver.exe发到Python的安装目录,例如 D:\python 。 然后再将Python的安装目录添加到系统环境变量的Path下面。

然后打开Python IDLE分别输入以下代码来启动不同的浏览器

启动谷歌浏览器

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://www.baidu.com/')



启动火狐浏览器
from selenium import webdriver

browser = webdriver.Firefox()
browser.get('http://www.baidu.com/')


启动IE浏览器
from selenium import webdriver

browser = webdriver.Ie()
browser.get('http://www.baidu.com/')

你可能感兴趣的:((二)Python+ Selenium自动化测试入门打开三大浏览器)