上ですでに説明したソリューションで、最も信頼できるソリューションはBrowsermob-Proxy
しかし、リモートグリッドマシンで作業している間、Browsermob-proxyは実際には役に立ちません。
これが私の場合の問題の修正方法です。うまくいけば、同様の設定を持つ人に役立つかもしれません。
- ModHeader拡張機能をChromeブラウザに追加します
Modheaderをダウンロードする方法は?リンク
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(C://Downloads//modheader//modheader.crx));
// Set the Desired capabilities
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
// Instantiate the chrome driver with capabilities
WebDriver driver = new RemoteWebDriver(new URL(YOUR_HUB_URL), options);
- ブラウザ拡張機能に移動し、ModHeaderのローカルストレージコンテキストIDをキャプチャします

- ModHeaderのURLに移動して、ローカルストレージコンテキストを設定します
。
// set the context on the extension so the localStorage can be accessed
driver.get("chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/_generated_background_page.html");
Where `idgpnmonknjnojddfkpgkljpfnnfcklj` is the value captured from the Step# 2
- 次に、を使用してリクエストにヘッダーを追加します
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: []
}]));");
ここtoken-1
でvalue-1
、、、、はtoken-2
、value-2
追加されるリクエストヘッダーと値です。
次に、必要なWebアプリケーションに移動します。
driver.get("your-desired-website");