开发者

Selenium - how to turn on firebug with console, script and net

开发者 https://www.devze.com 2023-02-04 05:46 出处:网络
I have set up a custo开发者_运维知识库m firefox profile and load it when selenium RC starts.The profile has firebug installed, and when I manually launch firefox with that profile, firebug is active.H

I have set up a custo开发者_运维知识库m firefox profile and load it when selenium RC starts. The profile has firebug installed, and when I manually launch firefox with that profile, firebug is active. However, when selenium launches that profile, firebug is in the lower right, but it is not enabled. How can I ensure it is enabled at launch? OR, how can I enable it (javascript or ?) - I am using the Java API.


If you create a new Firefox profile and assign it to your driver, you need to set the extensions.firebug.allPagesActivation value of the newly created firefox profile to on.

For example in Ruby, with Capybara:

profile = Selenium::WebDriver::Firefox::Profile.new
profile.add_extension("./firebug-1.10.6.xpi")

profile["extensions.firebug.console.enableSites"] = true
profile["extensions.firebug.net.enableSites"]     = true
profile["extensions.firebug.script.enableSites"]  = true
profile["extensions.firebug.allPagesActivation"]  = "on"

Capybara::Selenium::Driver.new app, :browser => :firefox, :profile => profile

See the documentation for Firebug Preferences


package com.mnas.technology.automation.utility;
import java.io.File;
import java.util.logging.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
/**
* @author manoj.kumar
* @email kumarmanoj.mtech@gmail.com
*/
public class AutomationUtility {
static Logger log = Logger.getLogger(AutomationUtility.class.getName());
public static void main(String[] args) {

// TODO Auto-generated method stub
try {
log.info("Starting Automation...");
log.info("Initializing WebDriver...");

FirefoxProfile ffProfile = new FirefoxProfile();
File firebug = new File(getApplicationPath()+"firebug-2.0.7.xpi");
ffProfile.addExtension(firebug);
ffProfile.setPreference("extensions.firebug.currentVersion", "2.0.7"); //(here you can include the version you currently have)
ffProfile.setPreference("extensions.firebug.showStackTrace", true);
ffProfile.setPreference("extensions.firebug.delayLoad", false);
ffProfile.setPreference("extensions.firebug.showFirstRunPage", false);
ffProfile.setPreference("extensions.firebug.allPagesActivation", "on");
ffProfile.setPreference("extensions.firebug.console.enableSites", true);
ffProfile.setPreference("extensions.firebug.defaultPanelName", "console");
WebDriver driver = new FirefoxDriver(ffProfile);
log.info("WebDriver object activated...");
driver.get("http://www.google.com");
String i = driver.getCurrentUrl();
log.info("CurrentURL===>"+i);
//driver.close();
} catch (Exception e) {
}
}
public static String getApplicationPath()
{
String relPath = System.getProperty("relpath");
return (relPath == null ? System.getProperty("user.dir") :  System.getProperty("user.home") + relPath) + File.separatorChar;
}
}


The way to do that is to open Firefox using your custom profile. Right-click on the Firebug icon and select "On for All Web Pages". Close Firefox and you should be good to go! That's how I do it.


Here's what works for me in Python:

fp = webdriver.FirefoxProfile()

fp.add_extension(extension='firebug-2.0.xpi')
fp.set_preference("extensions.firebug.currentVersion", "2.0") #Avoid startup screen
fp.set_preference("extensions.firebug.console.enableSites", "true")
fp.set_preference("extensions.firebug.net.enableSites", "true")
fp.set_preference("extensions.firebug.script.enableSites", "true")
fp.set_preference("extensions.firebug.allPagesActivation", "on")
driver = webdriver.Firefox(firefox_profile=fp)


go to the firefox profile location (which is in your java / c# code) open firefox from that location. make all your required settings close and restart firefox browser this time with your webdriver. that's it, it solves your problem !!

0

精彩评论

暂无评论...
验证码 换一张
取 消