Browser Automation with Python and Selenium — 3: Architecture
Bird’s eye view of Selenium applications

In the previous post, we looked at a simple, complete example. I will try to explain the high-level architecture of Selenium applications in this post.
Primary Building Blocks
- Selenium Client Libraries: Selenium Client Libraries or Selenium Language Bindings allow us to write automation scripts in the language of our choice like Python, Ruby, Java, etc.
- JSON Wire Protocol: JSON Wire Protocol is a REST-based API that is responsible for communication between the selenium scripts and the browser drivers.
- Browser Drivers: Selenium script communicates with the actual browser through the related browser driver. Browser drivers are responsible for controlling the real browser. The driver runs on the same system as the browser. Selenium framework does not need to know the implementation details of different web browsers thanks to drivers.
- Browsers: These are the actual browsers on which the desired automation tasks are performed. They receive the command from the driver and call the respective method to accomplish the task. After executing the command they return the response through the same route.

Types of Communication
Selenium WebDriver talks to browsers in 2 different ways: direct and remote.
1. Direct Communication
WebDriver talks to a browser through a driver. WebDriver, browser driver, and the real browser are on the same system in this type of communication. WebDriver passes commands and receives responses through the same route.

2. Remote Communication
Communication can also be remote through Selenium Server or RemoteWebDriver. In this case, RemoteWebDriver runs on the same system as the driver and the browser. Commands are sent and received over the remote webdriver.

Another way of remote communication is through Selenium Server or Selenium Grid components. They talk to the browser driver on the host system.

As stated in the official documentation
“WebDriver has one job and one job only: communicate with the browser via any of the methods above.”
Steps of Communication
driver = Chrome()
driver.get("https://www.python.org")
What happens when the above code snippet is executed?
- Selenium WebDriver launches browser-specific server first.
- An HTTP request is created and sent to the browser driver(in this case chromedriver) using JSON Wire Protocol over HTTP.
- The browser driver receives the HTTP request.
- The browser driver sends the request to the real browser(Chrome) via the HTTP server.
- The command is executed on the browser.
- The response is sent back to the browser driver by the browser which is sent back to the automation script finally.