modify Header Value (HTTP Headers)

141 views
Skip to first unread message

Fabio Giusti

unread,
Apr 15, 2020, 1:09:03 PM4/15/20
to Selenium Users
good evening
I have to test a site, that to access it I have to modify the header, through addon I have no problems, but with selenium I can't access it, by chance do you know how I can do it?

addon is Firefox's Modify Header Value (HTTP Headers), how should I put it in Java code ??

Thank you all
Fabio

Joe Ward

unread,
Apr 15, 2020, 5:21:58 PM4/15/20
to seleniu...@googlegroups.com
The current version of Selenium has no API for this, the next version may via developer tools but I haven't been keeping track of it. As far as I know people currently do things like this via a proxy e.g. BrowserMob Proxy. 

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/577928db-9d1f-40cf-89fa-da02ea3cd078%40googlegroups.com.

Serguei Kouzmine

unread,
Apr 15, 2020, 11:16:46 PM4/15/20
to Selenium Users
The 4.0.0.alphax versions of Selenium driver  jars
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.0.0-alpha-5
offer a big number of Chrome DevTools API wrappers, in particular the
See the integration test in
https://github.com/SeleniumHQ/selenium/blob/master/java/client/test/org/openqa/selenium/devtools/ChromeDevToolsNetworkTest.java#L126

Map<String, Object> headers = new HashMap<>();
headers.put("customHeaderName", "customHeaderValue");
Headers headersData = new Headers(headers);
chromeDevTools.send(Network.setExtraHTTPHeaders(headersData));
// add event listener to verify that requests are sending with the custom //
chromeDevTools.addListener(Network.requestWillBeSent(),
o -> System.err.println("addCustomHeaders Listener invoked with "
+ o.getRequest().getHeaders().get("customHeaderName")));
driver.get("https://apache.org");

will produce 

addCustomHeaders Listener invoked with customHeaderValue

but not sure if it supported by any other browser than chrome / chromium 
Reply all
Reply to author
Forward
0 new messages