How to use addCustomRequestHeader method in selenium?

I tried to use the addCustomRequestHeader method to set a custom header for selenium requests. Below is the source code

Selenium sel = new DefaultSelenium("localhost",4444,"*firefox","http://www.google.com"); sel.start("addCustomRequestHeader=true"); // sel.start(); sel.addCustomRequestHeader("mycustomheader","automation"); sel.open("http://www.google.com/"); 

This code did not add a header to the request. I tried to find request headers using Fiddler. Does anyone know what I'm doing wrong here? Any help would be appreciated

+6
source share
1 answer

You need to run selenium in proxy injection mode

 java -jar selenium-server-standalone.jar -proxyInjectionMode 

Then you can add custom request headers like this (in Python)

 sel.start("addCustomRequestHeader=true") sel.add_custom_request_header("mycustomheader","automation") sel.open('http://www.google.com') 

To find out if a custom header has been applied, check the tab on which the selenium server is running. In console messages you should see something like this

 INFO - Command request: addCustomRequestHeader[mycustomheader, automation] on session INFO - Got result: OK on session 
+1
source

Source: https://habr.com/ru/post/895917/


All Articles