Web Element in Selenium is a class or interface?

To answer this question, we have to take a look at the source code of Selenium WebDriver. The source code can be found here.

In that source code, it’s clearly mentioned that WebElement is an interface. The clear and concise code of WebElement interface is mentioned below.



import java.util.List;

public interface WebElement extends SearchContext, TakesScreenshot {

	void click();

	void sendKeys(CharSequence... keysToSend);

	void clear();

	String getTagName();

	default String getDomProperty(String name) {
		throw new UnsupportedOperationException("getDomProperty");
	}

	default String getDomAttribute(String name) {
		throw new UnsupportedOperationException("getDomAttribute");
	}

	String getAttribute(String name);

	default String getAriaRole() {
		throw new UnsupportedOperationException("getAriaRole");
	}

	default String getAccessibleName() {
		throw new UnsupportedOperationException("getAccessibleName");
	}

	boolean isSelected();

	boolean isEnabled();

	String getText();

	@Override
	 findElements(By by);

	@Override
	WebElement findElement(By by);

	default SearchContext getShadowRoot() {
		throw new UnsupportedOperationException("getShadowRoot");
	}

	boolean isDisplayed();

	Point getLocation();

	Dimension getSize();

	Rectangle getRect();

	String getCssValue(String propertyName);
}

So, as mentioned above, the WebElement interface has various abstract methods. And RemoteWebElement.java class implements this WebElement interface as mentioned in the source code.

To find more post on Selenium WebDriver please click here.