DEV Community

Deepikandas
Deepikandas

Posted on • Edited on

Selenium:What is WebElement?

What is a HTML Element?
A HTML element = an HTML tag + its content + attributes
Example:
Login
Here:
β†’ element type
id="loginBtn" β†’ attribute
Login β†’ visible content

So this entire piece is a HTML element (button element).


What is a WebElement in Selenium?

πŸ‘‰ A WebElement is a representation of an HTML element in Selenium.
A WebElement in Selenium is an interface that represents an HTML element on a web page. It provides methods to interact with web elements like clicking, typing, and reading attributes.”
In simple terms:
A WebElement is a Java object that represents an element in the web page DOM (like a button, textbox, checkbox, link, etc.)
Simple Meaning

βœ” HTML element lives in browser DOM
βœ” Selenium creates a WebElement object to control it
WebElement vs DOM Element (Core Difference)
🌐 1. DOM Element (Browser Side Concept)

A DOM element is the actual element present inside the browser’s page structure.

When a webpage loads, the browser converts HTML into a DOM (Document Object Model) tree.

Example HTML:

<button id="login">Login</button>
Enter fullscreen mode Exit fullscreen mode

In the browser DOM, this becomes a node like:

DOM Tree
 └── button#login
Enter fullscreen mode Exit fullscreen mode

πŸ”₯ Key point:
It exists inside the browser memory
It is part of the rendered page structure
JavaScript directly interacts with it.
WebElement (Selenium Side Concept)

A WebElement is a Selenium representation (proxy/reference) of a DOM element.

When you write:

WebElement loginBtn = driver.findElement(By.id("login"));

πŸ‘‰ Selenium does NOT store the actual button
πŸ‘‰ It stores a reference (locator + session info) to that DOM element

Top comments (0)