zoukankan      html  css  js  c++  java
  • webdriver高级应用- 启动FireFox的同时打开Firebug

    1. 首先本机Firefox浏览器需要安装一下firebug插件,具体怎么安装这里不赘述,网上教程很多。

    2. 具体自动化实现的代码如下:

    #encoding=utf-8
    from selenium import webdriver
    import unittest, time
    from selenium.webdriver.common.keys import Keys
    
    class TestDemo(unittest.TestCase):
    
        def test_openFireBug(self):
            # 找到自定义配置文件路径
            profilePath = r"C:UserswuxiaohuaAppDataRoamingMozillaFirefoxProfilesg6m1cswj.default"
            # 将自定义配置文件加载到FirefoxProfile实例中
            profile = webdriver.firefox.firefox_profile.FirefoxProfile(profilePath)
            # 将添加了新配置文件的Firefox浏览器首页设为百度主页,
            # 以便启动浏览器后将直接跳转到百度首页
            profile.set_preference("browser.startup.homepage", "http://www.baidu.com")
            # 设置启动浏览器的同时主页不为空白页
            profile.set_preference("browser.startup.page", 1)
            # 自动打开firebug
            profile.set_preference("extensions.firebug.allPagesActivation", "on")
            # 启用firebug网络面板功能
            profile.set_preference("extensions.firebug.net.enableSites", True)
            # 启用firebug Cookies面板功能
            profile.set_preference("extensions.firebug.cookies.enableSites", True)
            # 启动自定义配置信息的Firefox浏览器
            driver = webdriver.Firefox(executable_path="e:\geckodriver", firefox_profile = profile)
            # 等待浏览器启动完成
            time.sleep(3)
            # 找到百度主页中的搜索输入框页面元素
            input = driver.find_element_by_id("kw")
            # 在搜索输入框中输入“selenium”
            input.send_keys("selenium")
            # input.send_keys(Keys.F12)
            # 等待30秒,人工确认上面一系列设置是否生效
            time.sleep(30)
            driver.quit()
    
    if __name__ == '__main__':
        unittest.main()
  • 相关阅读:
    PHP实现微信退款的分析与源码实现
    thinkphp对180万数据批量更新支持事务回滚
    在线工具
    php连接redis
    Redis PHP连接操作
    阿里大于短信接口整合TP5
    Unity3d中如何查找一个脚本被挂在那些预设上面?
    泰课在线夜猫的贪食蛇
    EasyTouch5ForSiki学院
    unity游戏热更新
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8717305.html
Copyright © 2011-2022 走看看