1
votes

Selenium : Selenium Automatically sets referer Header

I am using selenium RC with chrome

My problem is that each time selenium opens a chrome instance it set the HTTP referer Header to this value "name":"Referer", "value":"https://localhost/selenium-server/core/RemoteRunner.html?sessionId=534b84df760b4422940a90dadd1bd60c&multiWindow=true&baseUrl=https%3A%2F%2Flocalhost%2Fems&debugMode=false"

My web application checks whether referer contains valid link (links which are part of web application) and if referer contains any other link it displays error.

Due to this i am not able to login to my web application using selenium

Is there any way to start selenium instance without "Referer" header or Referer as blank

1

1 Answers

0
votes

According this page there exist this Chrome switch

--no-referrers  Don't send HTTP-Referer headers.

In Java I would do it like this:

ChromeDriverService service = ChromeDriverService.createDefaultService();
File file = new File(RegulationUI.class.getResource("/chromedriver.exe").toURI());
System.setProperty(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, file.getAbsolutePath());
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized"); //Chrome starts always maximized
options.addArguments("--no-referrers"); // no HTTP referer will be send
WebDriver driver = new ChromeDriver(service,options); //starts Chrome
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); //imlpicitly wait 30s for fage to load

EDIT I completly missed the Selenium-RC thing. Reading the javadoc I realised there can be a way:

DefaultSelenium selenium = new DefaultSelenium("ServerHost", 8080, "path/to/chrome/chrome.exe --no-referrers", "start-url.com");

Anyways I never tried it, so I don't know if it will work

EDIT2

I foung out, that you can send String to the start() command. So if above does not work you can also try:

 selenium.start("--no-referrers");