python webdriver api-对启动的火狐浏览器添加配置

Webdriver启用的火狐不带插件,可以自已进行配置

先找到火狐的安装路径

C:\Program Files\Mozilla Firefox

 

步骤说明

在CMD中使用cd命令进入firefox.exe文件所在目录(比如:C:\Program Files\Mozilla Firefox),
并输入firefox.exe -ProfileManager -no-remote命令,然后按Enter键,
调出“Firefox – 选择用户配置文件”操作窗口


如果firefox.exe -ProfileManager -no-remote 执行弹出一个页面说找不到路径,解决方法:
在火狐的菜单“帮助”下,选择“故障排除信息”,点击后,在弹出的页面中找到“配置文件夹 ”的
选项,点击“打开文件夹”,可以获取默认配置文件的全路径。


进入mac的火狐路径:/Applications/Firefox.app/Contents/MacOS
执行:firefox -profilemanager 
新建profile

 

调出配置窗口,cmd下进入火狐的路径,执行命令firefox.exe -ProfileManager -no-remote
选择启动时不询问并使用选定的配置文件

 

可以创建配置文件
在创建的时候找到刚才做了配置的账户的路径

找到刚才做了配置的账户的路径替换到python文件里

C:\Users\Lenovo\AppData\Roaming\Mozilla\Firefox\Profiles\euhvixdt.default

 

#encoding=utf-8

from selenium import webdriver

from selenium.common.exceptions import NoSuchElementException

import unittest, time

 

class TestFailCaptureScreen(unittest.TestCase):

 

    def setUp(self):

        # 创建存储自定义配置文件的路径变量

        #proPath = "C:\\Users\\wuxiaohua\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\tbbmxtkv.webdriver"

        proPath = "C:\Users\Lenovo\AppData\Roaming\Mozilla\Firefox\Profiles\euhvixdt.default"

        # 加载自定义配置文件到FirefoxProfile实例中,

        # 等价profile = webdriver.FirefoxProfile(proPath)

        profile = webdriver.firefox.firefox_profile.FirefoxProfile(proPath)

        # 将添加了新配置文件的Firefox浏览器首页设为搜狗主页

        profile.set_preference("browser.startup.homepage", "http://www.sogou.com")

        # 设置开始页面不是空白页,0表示空白页,

        # 这一步必须做,否则设置的主页不会生效

        profile.set_preference("browser.startup.page", 1)

        # 启动带自定义配置文件的Firefox浏览器

        self.driver = webdriver.Firefox(executable_path="d:\\geckodriver", firefox_profile=profile)

 

    def testSoGouSearch(self):

        # 等待5秒,以便浏览器启动完成

        time.sleep(5)

        try:

            # 找到搜狗主页搜索输入框页面元素

            searchBox = self.driver.find_element_by_id("query")

            # 在找到的搜索输入框中输入“光荣之路自动化测试”

            searchBox.send_keys(u"光荣之路自动化测试")

            # 找到搜索按钮,并点击

            self.driver.find_element_by_id("stb").click()

            time.sleep(10)

        except NoSuchElementException, e:

            print "修改带自定义配置文件的浏览器主页不成功!"

 

    def tearDown(self):

        # 退出Firefox浏览器

        self.driver.quit()

 

if __name__ == '__main__':

unittest.main()

 

D:\test>python test.py

.

----------------------------------------------------------------------

Ran 1 test in 52.252s

 

OK

转载来自:https://www.cnblogs.com/xiaxiaoxu/p/9206341.html

转载于:https://www.cnblogs.com/yblafxw/p/10483172.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值