Browsermob-Proxy
is a dependable resolution, However whereas working with the distant grid machine, Browsermob-proxy is not actually useful. Alternatively, I discovered this as a working resolution for my setup.
Hopefully, it is going to be helpful for somebody with the same setup.
- Add the ModHeader extension to the chrome browser
Find out how to obtain the Modheader? Hyperlink
ChromeOptions choices = new ChromeOptions();
choices.addExtensions(new File(C://Downloads//modheader//modheader.crx));
// Set the Desired capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, choices);
// Instantiate the chrome driver with capabilities
WebDriver driver = new RemoteWebDriver(new URL(YOUR_HUB_URL), choices);
- Go to the browser extensions and seize the Native Storage context ID of the ModHeader
- Navigate to the URL of the ModHeader to set the Native Storage Context
.
// set the context on the extension so the localStorage may be accessed
driver.get("chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/_generated_background_page.html");
The place `idgpnmonknjnojddfkpgkljpfnnfcklj` is the worth captured from the Step# 2
- Now add the headers to the request utilizing
Javascript
.
((Javascript)driver).executeScript(
"localStorage.setItem('profiles', JSON.stringify([{ title: 'Selenium', hideComment: true, appendMode: '',
headers: [
{enabled: true, name: 'token-1', value: 'value-1', comment: ''},
{enabled: true, name: 'token-2', value: 'value-2', comment: ''}
],
respHeaders: [],
filters: []
}]));");
The place token-1
, value-1
, token-2
, value-2
are the request headers and values which can be to be added.
-
Now navigate to the required web-application.
driver.get("your-desired-website");