Selenium is a browser automation framework. It drives Chrome, Firefox, and other browsers the way a person would: clicking buttons, filling forms, reading the rendered page. It is the standard tool for end-to-end UI testing, and it is very good at that job.
People still ask whether Selenium can test APIs. The honest answer is that you can make it issue HTTP calls, but it is the wrong tool for the work. This guide explains exactly why, shows what API testing through Selenium actually looks like, and points you to tools that are built for the job. The goal is to save you from a setup that will frustrate you later.
Why Selenium and API testing do not match
An API test sends an HTTP request directly to a server and checks the response: status code, headers, body, timing. There is no user interface involved. The test should be fast, isolated, and cheap to run thousands of times.
Selenium does the opposite by design. It launches a real browser, loads pages, and waits for JavaScript to render. That browser is the entire point when you are testing a UI, and it is pure overhead when you are testing an API. A request that a dedicated client sends in tens of milliseconds becomes a multi-second affair once you involve a browser process, a WebDriver session, and page rendering.
There is a deeper mismatch too. Selenium’s whole API is about elements on a page: find this button, read this text, wait for this element. An HTTP response is not a page. It has no DOM. So Selenium gives you nothing useful for inspecting a JSON body, asserting on a header, or checking a status code. You end up working around the tool instead of with it.
The cost is not only speed. Browser-based tests are famously flaky. They fail because a page took a moment longer to render, because a WebDriver session dropped, or because a browser update changed some timing. An API test should be deterministic: the same request produces the same response, and a failure means something genuinely broke. Routing API checks through Selenium imports all of that browser flakiness into a layer that has no reason to be flaky at all. Over time, a flaky suite trains the team to shrug off red builds, which defeats the point of testing. The distinction between validation and verification is a good lens here: Selenium verifies the rendered experience, while API testing validates the contract underneath it.
What “API testing with Selenium” actually means
When articles claim Selenium can test APIs, they usually mean one of two workarounds. Neither makes Selenium an API testing tool. They just route HTTP through or alongside it.
Option one: use Selenium’s JavaScript executor. Selenium can run arbitrary JavaScript in the browser it controls. Modern browsers have the fetch API, so you can ask the browser to make a request and hand the result back to your test code:
JavascriptExecutor js = (JavascriptExecutor) driver;
Object status = js.executeAsyncScript(
"const callback = arguments[arguments.length - 1];" +
"fetch('https://jsonplaceholder.typicode.com/users/1')" +
" .then(r => callback(r.status))" +
" .catch(e => callback('error: ' + e));"
);
System.out.println("Status code: " + status);
This works. It also means you have started a browser, a WebDriver, and a JavaScript bridge purely to make one HTTP call that a normal HTTP client would make directly. You also inherit browser constraints like CORS, which a server-to-server API test never has to think about.
Option two: ignore Selenium and use a real HTTP library next to it. In a Java project this means pairing Selenium with REST Assured for the API parts:
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
given()
.when()
.get("https://jsonplaceholder.typicode.com/users/1")
.then()
.statusCode(200)
.body("email", equalTo("Sincere@april.biz"));
Notice that the actual API testing here is done entirely by REST Assured. Selenium contributes nothing. The two libraries just happen to live in the same project. That is fine, but it is not “API testing with Selenium.” It is API testing with a proper API testing library, with Selenium present for unrelated UI tests.
When mixing them is reasonable
There is one legitimate case for HTTP work inside a Selenium suite, and it is worth being clear about. Selenium UI tests often need setup or teardown that is faster to do over the API than through the browser.
Say you have a UI test that checks the order history page. To test it, an order has to exist. Clicking through the entire checkout flow in the browser just to create that order is slow and brittle. Instead, your test makes a direct API call to create the order, then uses Selenium only for the part that genuinely needs a browser: loading the history page and verifying the order shows up.
That is sound practice. The API call is a means to an end, not the thing under test. The API call should still go through a real HTTP client, not the JavaScript executor. So even in this case, Selenium is not doing the API testing. It is doing the UI testing, and a proper HTTP client handles the API side.
This setup-over-API pattern is common enough that most mature test suites adopt it deliberately. It keeps the slow, browser-driven part of the suite as small as possible, reserved for the handful of journeys that genuinely need a rendered page. Everything else, including all the data preparation and most of the verification, happens over fast HTTP calls. The result is a suite that runs in minutes instead of hours and fails for real reasons. For the broader picture of how UI and automated layers fit together, see functional testing versus automated testing.
Use a tool built for API testing
If your goal is to test APIs, use something designed for it. The difference is not small. A real API testing tool gives you request building, environment management, assertions on status, headers, and body, request chaining, data-driven runs, and CI integration, without launching a browser.
Your options fall into a few groups:
| Approach | Best for | API testing fit |
|---|---|---|
| Selenium | UI / browser end-to-end tests | Poor. Not designed for HTTP. |
| REST Assured / requests / supertest | API tests inside a code project | Good. Real HTTP libraries. |
| Postman, Insomnia, Talend API Tester | Manual and scripted API testing | Good. Purpose-built clients. |
| Apidog | Full API lifecycle: design, debug, mock, test, document | Strong. One workspace for all of it. |
If you prefer code, an HTTP library like REST Assured in Java, requests in Python, or supertest in Node is the right call. These libraries make a request and hand you back the response directly, with assertion helpers built for status codes and JSON bodies. There is no browser, no WebDriver, and no rendering, so a full suite runs fast and fails only when the API itself changes.
If you want a visual workspace, Apidog is an all-in-one API platform that covers designing the API, debugging requests, mocking endpoints, building automated test scenarios, and generating documentation, all in one project. You build assertions visually or with scripts, chain requests into multi-step flows, run data-driven iterations, and execute everything in CI. It also imports OpenAPI and Postman files, so an existing API is quick to bring in. None of it involves a browser, because none of it should. You can download Apidog to try it against a real API.
For teams that want a code-first framework, the guides on Robot Framework for API automation and building an API automation testing framework cover approaches that, unlike Selenium, are actually suited to HTTP testing.
The honest takeaway
Selenium is excellent software for what it was built to do, which is automate browsers. API testing is not that. You can technically push HTTP through Selenium’s JavaScript executor, and you can keep an HTTP library in the same project as Selenium, but in neither case is Selenium adding value to the API testing itself.
Choosing the wrong tool is not a neutral decision. It makes your tests slower, harder to maintain, and prone to failures that have nothing to do with your API. Reach for a tool built for the job. Your test suite will be faster, more reliable, and far easier to reason about. The roundup of the best automated testing platforms is a good place to compare purpose-built options.
Frequently asked questions
Can Selenium test REST APIs at all?
It can issue HTTP requests through the browser’s JavaScript executor, so in a narrow technical sense yes. But Selenium has no features for inspecting responses, asserting on JSON, or checking headers, and it carries the full overhead of a browser. It is not a REST API testing tool, and using it as one creates slow, fragile tests.
Why do some tutorials show Selenium with REST Assured?
Because the API testing in those tutorials is done entirely by REST Assured, which is a real HTTP testing library. Selenium is just present in the same project for unrelated UI tests. The pairing is fine, but it does not mean Selenium is testing the API. REST Assured is.
Is it ever okay to make API calls in a Selenium test?
Yes, for setup and teardown. Creating test data over the API is faster and more reliable than clicking through the UI to produce it. The API call supports the UI test rather than being the thing under test, and it should still use a proper HTTP client, not Selenium’s JavaScript executor.
What should I use instead of Selenium for API testing?
For code-first testing, an HTTP library such as REST Assured, Python’s requests, or supertest for Node. For a visual workspace, a dedicated API platform like Apidog, or clients like Postman, Insomnia, and Talend API Tester. All of these are built for HTTP and avoid the browser overhead Selenium imposes.
Does using Selenium for API tests slow down my CI pipeline?
Significantly. Each Selenium-based API call starts a browser process and a WebDriver session, turning a sub-second HTTP request into a multi-second operation. Across a suite, that adds up to long, flaky pipeline runs. A dedicated API testing tool runs the same checks far faster because it never launches a browser.
