0

I'm trying to write a test against a site that authenticate's by checking some headers. In other frameworks it's possible to add headers to the driver but I can't see anything like that in Selenium.

Is there a way to add request headers to selenium webdriver? Ideally on a per-test case so the existing suite doesn't have to use headers it doesn't need.

1
  • What framework have you tried? What request are you sending with Selenium? Selenium is a browser automation tool. If you can access the site using a browser, then it should be accessible using Selenium. If you are sending HTTP requests, then selenium is not the tool.
    – S A
    CommentedNov 14, 2024 at 11:21

1 Answer 1

0

Why not use basic HttpClient

<dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.14</version> </dependency> 

or you can use RestTemplate or WebClient depending upon your requirement.

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.0.2.RELEASE</version> </dependency> 

Since you are trying to setup headers, you are not testing UI but rather your endpoints. Selenium is not supposed to be used like this. Selenium automates actions by a user in browser. Since user doesn't/cannot specify header, you shouldn't try that either.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.