关于UI自动化浏览器驱动路径设置

做UI自动化测试需要用到浏览器驱动,现在高版本的浏览器都要带驱动,只有低版本selenium2.48+火狐35才免驱。那么问题来了,selenium版本过低有时候兼容性就差。

一、使用高版本的时候需要带驱动,通常将驱动放到项目结构下的文件夹中,最简单的设置方式:

driver = webdriver.Chrome(executable_path=r'D:\项目名称\driver\chromedriver.exe')
driver.get('https://mail.163.com/')

在这里插入图片描述
二、第二种写法:

i_path = os.getcwd()  #获取当前文件路径
cur_path = os.path.dirname(i_path) #当前文件上一层路径
web_path = os.path.join(cur_path+'\\'+"driver"+'\\'+"chromedriver.exe")
print(web_path)
driver = webdriver.Chrome(executable_path=web_path)
driver.get('https://mail.163.com/')

在这里插入图片描述

三、第三种方法比较正规,符合整个项目结构和环境考虑。
1.首先要写一个专门读取配置文件ini的py文件。

import configparser
import codecs

class ReadConfig:
    """
    专门读取配置文件的,.ini文件格式
    """
    def __init__(self, filename):
        configpath = filename
        fd = open(configpath)
        data = fd.read()
        if data[:3] == codecs.BOM_UTF8:
            data = data[3:]
            files = codecs.open(configpath, "w")
            files.write(data)
            files.close()
        fd.close()
        self.cf = configparser.ConfigParser()
        self.cf.read(configpath)

    def getValue(self, env, name):   #该方法返回的是项目路径
        return self.cf.get(env,name)


配置文件:
在这里插入图片描述

在这里插入图片描述
其中projectConfig就是配置文件中的[projectConfig],如果需要多个,也可以配置。

火狐浏览器历史版本驱动:http://ftp.mozilla.org/pub/firefox/releases/
谷歌驱动:http://chromedriver.storage.googleapis.com/index.html
IE驱动:http://selenium-release.storage.googleapis.com/index.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值