marwaha.ks
marwaha.ks

Reputation: 549

By elements and IWebElement

Could you explain the difference between By element and IWebElements.

Also, why doesn't selenium use one or the other?

[FindsBy(How = How.XPath, Using = "//div[@class='example']/h3")] 
private IWebElement _heading;

and

var byElement = By.XPath("//div[@class='example']/h3")

Upvotes: 2

Views: 4756

Answers (1)

alecxe
alecxe

Reputation: 474031

IWebElement is a selenium Web Element class which represents an HTML element (body, table, tr etc) on a page in your selenium automation code. Through the IWebElement instance, you can interact with an element, retrieve it's attributes and properties.

By.something() is just a locator - the way you tell selenium how to locate the element within the document so that you can make an IWebElement instance. The are different built-in locators, like By.Xpath, By.CssSelector, By.Id etc.

Upvotes: 6

Related Questions