Skip to content

Add header in Selenium #46

Description

@sjoshid

Hi,
Im very close to using this but there's only one thing stopping me. In Firefox, when I want to send a request with a header. Without this header, my request is going to fail.

I tried this:

final ProfilesIni pi = new ProfilesIni();
final FirefoxProfile profile = pi.getProfile("default");
profile.setPreference("browser.download.folderList",
      2); // 0: Desktop, 1: Downloads, 2: Custom Location
final Path abs = downloadedFilePath.toAbsolutePath();
profile.setPreference("browser.download.dir", abs.toString());

final String commonPassword = repProperties.getCommonPassword();
final String usernamePassword = username + ":" + commonPassword;
final String encodedString = Base64.getEncoder().encodeToString(usernamePassword.getBytes());

// These prefs dont work. 
/*profile.setPreference("modifyheaders.headers.count", 1);
profile.setPreference("modifyheaders.headers.action0", "Add");
profile.setPreference("modifyheaders.headers.name0", "Authorization");
profile.setPreference("modifyheaders.headers.value0", "Basic " + encodedString);
profile.setPreference("modifyheaders.headers.enabled0", true);
profile.setPreference("modifyheaders.config.active", true);
profile.setPreference("modifyheaders.config.alwaysOn", true);*/

// Neither do these. 
profile.setPreference("modheader.headers.count", 1);
profile.setPreference("modheader.headers.action0", "Add");
profile.setPreference("modheader.headers.name0", "Authorization");
profile.setPreference("modheader.headers.value0", "Basic " + encodedString);
profile.setPreference("modheader.headers.enabled0", true);
profile.setPreference("modheader.headers.config.active", true);
profile.setPreference("modheader.headers.config.alwaysOn", true);

final FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("acceptInsecureCerts", true);
//firefoxOptions.setHeadless(true); sj_todo remove uncomment
firefoxOptions.setProfile(profile);

logger.debug("Creating reports at {}", abs);
final FirefoxDriver webDriver = new FirefoxDriver(firefoxOptions);
webDriver.installExtension("path-to-xpi");
return webDriver;

Another way is to load the modheader profile (that has the header I need) on startup. But I cant find a way to import automatically on startup either.

Any suggestions?

Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions