Selenium FF WebDriver运行时开启firebug的2种方式

本文介绍两种在Firefox WebDriver中自动激活Firebug的方法。第一种方法通过使用Actions类的sendKeys方法发送F12快捷键激活Firebug;第二种方法是设置Firefox的偏好设置,将extensions.firebug.allPagesActivation设置为'on',使Firebug在所有页面上自动激活。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一次我实测FF webdriver 加载firefoxhttp://www.cnblogs.com/tobecrazy/p/3997375.html

那么问题就来了,既然能加载firebug能否在运行时候直接激活firebug

效果如下:

针对这个情况,我们有两种solutions

方法1:使用firebug的快捷键F12激活firebug

不过这需要使用Actions class 的sendKeys method,使用sendKeys方法别忘了添加perform() 方法 否则不执行的

           File file=new File("C:\\webdriver\\firebug-2.0.4-fx.xpi");//设置Firebug路径
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("network.proxy.type", 2);
            profile.setPreference("network.proxy.autoconfig_url", "http://proxy.successfactors.com:8083"); //自动代理配置
          
            try {
                //add firebug
                profile.addExtension(file);
                profile.setPreference("extensions.firebug.currentVersion", "2.0.4");//设置firebug 版本
   
                 
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            WebDriver driver = new FirefoxDriver(profile);
           
            driver.get("http://www.dbyl.cn");
            Actions actions=new Actions(driver);
            //F12 is a short cut of active firebug
            //do not forget perform
            actions.sendKeys(Keys.F12).perform();
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

另外一种方法是直接使用Firefox的setPreference

我们注意到:FF 的extensions.firebug.allPagesActivation设置为ON,firebug会被active

            File file=new File("C:\\webdriver\\firebug-2.0.4-fx.xpi");//设置Firebug路径
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("network.proxy.type", 2);
            profile.setPreference("network.proxy.autoconfig_url", "http://proxy.successfactors.com:8083"); //自动代理配置
          
            try {
                //add firebug
                profile.addExtension(file);
                profile.setPreference("extensions.firebug.currentVersion", "2.0.4");//设置firebug 版本
                //active firebug extensions
                profile.setPreference("extensions.firebug.allPagesActivation", "on");
                 
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            WebDriver driver = new FirefoxDriver(profile);
           
            driver.get("http://www.dbyl.cn");
            Actions actions=new Actions(driver);
           
            driver.manage().window().maximize();
            driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值