Selenium FF WebDriver運行時開啟firebug的2種方式


上一次我實測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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM