Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How webdriver communicates/works with browser?

enter image description here

I'm using Selenium for web crawler, it works fine at most time, but some websites can detect it, so I decided to learn more deeply.

After some search, i found "Chrome DevTools Protocol" and "Json Wire Protocol".

"Json Wire Protocol" works between Selenium and Webdriver as implementations for Python Java C# and other languages, so they can communicate with Webdriver by unified protocol, several articles explained this point.

But I can't find any article about how Webdriver communicate with browser, a few article says ChromeDriver communicates with Chrome by "Chrome DevTools Protocol", but they didn't explain details, so I'm not sure is this point correct.

How Browser receives command from Browser Driver and executes it?

like image 512
Fire0594 Avatar asked Sep 15 '25 09:09

Fire0594


2 Answers

WebDriver basically lets you define driver object for 7 known browsers.

Webdriver is an interface and RemoteWebDriver is class that implements Webdriver Interface.

All mentioned 7 classes (chromedriver, safaridriver, edgeDriver and so) extend RemoteWebDriver class.

Below is the communication flow between webdriver and broswer :

  • for each Selenium command, a HTTP request is created and sent to the browser driver

  • the browser driver uses a HTTP server for getting the HTTP requests

  • the HTTP server determines the steps needed for implementing the Selenium command

  • the implementation steps are executed on the browser

  • the execution status is sent back to the HTTP server

  • the HTTP server sends the status back to the automation script

Read more about it here

enter image description here

like image 176
cruisepandey Avatar answered Sep 17 '25 19:09

cruisepandey


On a high level selenium webdriver interacts with browser and it will not translate to Javascripts command, Basically our Java or Python Code will be sent as an api get and post request in JSON wire protocol. as explained in the above answer browser webdriver interacts with the real browser as a HTTP Request.

Every Browser Driver uses an HTTP server to receive HTTP requests. Once the URL reaches the Browser Driver, then it will pass that request to the real browser over HTTP. Once done, the commands in your Selenium script will be executed on the browser.

If the request is POST request, then there will be an action on the browser. If the request is a GET request then the corresponding response will be generated at the browser end. It will be then sent over HTTP to the browser driver and the Browser Driver over JSON Wire Protocol and sends it to the UI.

  • Test commands are converted into an HTTP request by the JSON wire protocol
  • Before executing any test cases, every browser has its own driver which initializes the server.
  • The browser then starts receiving the request through its driver.

for more information please refer the below site

BrowserStack :- https://www.browserstack.com/guide/selenium-webdriver-tutorial

Selenium Dev:- https://www.selenium.dev/documentation/en/webdriver/understanding_the_components/

Edureka:- https://www.edureka.co/blog/selenium-webdriver-architecture/

like image 39
LearnerLaksh Avatar answered Sep 17 '25 19:09

LearnerLaksh