Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use addCustomRequestHeader method in selenium?

I was trying to use addCustomRequestHeader method to set a custom header for selenium requests. Given 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 didn't add the header to the request. I tried to look up the request headers using Fiddler. Does any one here know what am I doing wrong here? Any help would be appreciated

like image 322
A.J Avatar asked Aug 25 '11 20:08

A.J


1 Answers

You need to start the selenium in proxy injection mode

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

You can then add custom requests headers like this (in Python)

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

To see if the custom header has been applied, check the tab that has the selenium server running. You should see something like this in the console messages

INFO - Command request: addCustomRequestHeader[mycustomheader, automation] on session 
INFO - Got result: OK on session 
like image 186
retornam Avatar answered Sep 28 '22 08:09

retornam