DEV Community

Cover image for Python Selenium architecture
Namrata saha
Namrata saha

Posted on

Python Selenium architecture

Selenium WebDriver architecture:

The architecture of Selenium WebDriver tells about the Working process of Selenium internally. Selenium is one of the browser’s automation framework, with which we can communicate with the browser and automate the end to end tests of web applications.

The API of selenium WebDriver helps in connecting between browser and languages. Every Browser has several logical executions on the browser. The above image represents multiple elements of Selenium WebDriver Architecture.

The main four components of Selenium WebDriver are:

  1. Selenium Client Library or Language Bindings
  2. Browser Driver
  3. Browsers.
  4. JSON(JavaScript Object Notation) WIRE PROTOCOL Over HTTP Client The significance of python virtual environment

Python Virtual Environment:
A Python Virtual Environment is an isolated space where we can work on our own Python projects, separately from our system installed Python.

we can set up our own libraries and dependencies without affecting the system Python.

To create a virtual environment in Python, we have to use “virtualenv”

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated Python virtual environments for them. This is one of the most important tools that most Python developers use.
**Example:

To create a virtual environment, you can use the virtualenv tool:
pip install virtualenv
virtualenv myenv
source myenv/bin/activate # On Windows: myenv\Scripts\activate

Once activated, you can install Selenium and other packages using pip.

Sample Selenium Script in Python

**from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

Set up the Chrome driver

service = Service()
driver = webdriver.Chrome(service=service)

Open a webpage

driver.get("https://example.com")

Find an element and print its text

element = driver.find_element(By.TAG_NAME, "h1")
print(element.text)

Close the browser

driver.quit()

Top comments (0)