How to send an http RequestHeader using Selenium 2?

Unfortunately you can not change headers with Selenium 2. This has been a conscious decision on the teams part as we are trying to create a browser automation framework that emulates what a user can do.


As per Alberto's answer you can add modify headers to the Firefox profile if you are using it:

FirefoxDriver createFirefoxDriver() throws URISyntaxException, IOException {
    FirefoxProfile profile = new FirefoxProfile();
    URL url = this.getClass().getResource("/modify_headers-0.7.1.1-fx.xpi");
    File modifyHeaders = modifyHeaders = new File(url.toURI());

    profile.setEnableNativeEvents(false);
    profile.addExtension(modifyHeaders);

    profile.setPreference("modifyheaders.headers.count", 1);
    profile.setPreference("modifyheaders.headers.action0", "Add");
    profile.setPreference("modifyheaders.headers.name0", SOME_HEADER);
    profile.setPreference("modifyheaders.headers.value0", "true");
    profile.setPreference("modifyheaders.headers.enabled0", true);
    profile.setPreference("modifyheaders.config.active", true);
    profile.setPreference("modifyheaders.config.alwaysOn", true);

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setBrowserName("firefox");
    capabilities.setPlatform(org.openqa.selenium.Platform.ANY);
    capabilities.setCapability(FirefoxDriver.PROFILE, profile);
    return new FirefoxDriver(capabilities);
}