• 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()
  • 相关阅读:
    intellij idea 热部署失效,需要手动编译类
    mac brew 安装包下载失败解决
    DataTemplate 之 ContentTemplate 的使用
    dataTemplate 之 ContentTemplate 的使用
    dataTemplate 的使用之listView
    dataTemplate 使用
    wpf中UserControl的几种绑定方式
    WPF教程(四)RelativeSource属性
    堆的概念
    哈夫曼(huffman)树和哈夫曼编码
  • 原文地址:https://www.cnblogs.com/qingqing-919/p/8717305.html
Copyright © 2020-2023  润新知