Selenium with C# 7 - Locators in Selenium | What is HTML Dom? What are HTML elements and attributes

preview_player
Показать описание
Locators In Selenium Webdriver

HTML DOM
HTML Element
HTML Element attributes
ISearchContext Interface
FindElement method
FindElements method
By Class
WebDriver Locators

HTML DOM
The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents.
It defines the logical structure of documents and the way a document is accessed and manipulated.

HTML Element
An HTML element usually consists of a start tag and end tag, with the content inserted in between.

ISearchContext interface
ISearchContext interface has only two methods
FindElement()
FindElements()
These methods will be abstract as ISearchContext is an interface.
ISearchContext interface is inherited by IWebElement and IWebDriver

FindElement() Method :
FindElement() method takes locator(By object) as an argument and returns a object of IWebElement.
FindElement() method navigates to entire HTML document and identifies the element in GUI, by taking reference of locator.
Finds the first webelement using the given method.
Parameters: By- The locating mechanism.
Returns: The first matching element on the current context.
Throws: NoSuchElementException -If no elements found

FindElements() method:
Finds all elements within the current context using the given mechanism.
Parameters: By-The locating mechanism in use
Returns: A list of all Webelements
If no elements found with locator, returns null

What is By Class?
All the locators are static methods, present in “By” class.
FindElement() and FindElements() methods uses By class to locate elements within a webpage.
Example for finding the element in DOM is
IWebElement element = driver.FindElement(By.Id(“UserName”));

Locators in selenium
Locators finds the element in HTML document
Locators are static methods present in By class
Locator methods return By object

Id() locator method:
Identify the element based on Id attribute.
Gets a mechanism to find elements by their ID.
public static By Id(string Id)
Parameters: The value of the "id" attribute to search for
Returns: A By object which locates elements by the value of the "id" attribute.

Name() locator method :
Identify the element based on name attribute.
Gets a mechanism to find elements by their name.
Public static By Name(string Name)
Parameters: The value of the “Name" attribute to search for
Returns: A By object which locates elements by the value of the “name" attribute.

ClassName() locator method:
Identify the element using class attribute
Gets a mechanism to find elements by their CSS class.
Public static By ClassName(string ClassName)
Parameters: The value of the “class" attribute to search for
Returns: A By object which locates elements by the value of the “class" attribute.

TagName() locator method:
Identify the element using HTML TagName.
Gets a mechanism to find elements by their tag name.
Public static By TagName(string Name)
Parameters: Name-The elements TagName.
Returns: A By object which locates elements by tagname.

LinkText() locator method:
Identify the element using name of the link.
Gets a mechanism to find elements by their link text.
Public static By LinkText(string LinkText)
Parameters: LinkText- The exact text to match against
Returns: A By object which locates elements by the exact link text

PartialLinkText() locator method :
Identify the element using part of link name.
Gets a mechanism to find elements by a partial match on their link text.
Public static By PartialLinkText(string LinkText)
Parameters: LinkText- The text to match against
Returns: A By object which locates elements that contains the given link text

CSSSelector() locator method :
Gets a mechanism to find elements by their cascading style sheet (CSS) selector.
Public static By CSSSelector(string Selector)
Parameters: Selector-CSS expression
Returns: A By object which locates elements by CSS selectors

XPath() locator method :
Identify the object using any attributes or visible text.
Gets a mechanism to find elements by an XPath query.
Public static By XPath(string XpathExpression)
Parameters: XpathExpression- The Xpath to use
Returns: A By object which locates elements via XPath

Ideal locator order(Locator priority)
Id
Name
Class
Tag name
Link text
Partial link text
CSSSelector
Xpath

Selenium locators Possible Interview Questions :
What are HTML DOM and HTML elements.
What is ISearchContext interface and explain its methods
Explain the types of locators

FindElement vs FindElements
Xpath locator
Selenium 8 locator
Selenium locator strategy
What is By class?
What is ISearchContext interface?
What is selenium locator priority?
What is a HTML element?
What is Document object model (DOM)?
What is an html attribute?
How to use Selenium locators?
What is FindElement method?
What is FindElements method?
Return type of FIndElements?
Рекомендации по теме
Комментарии
Автор

Thank you for watching this video. Cheers! would you mind hitting *_like_* button and *_subscribe_* to our channel! That will be awesome. We would be grateful to you. And also share this video in your circle via whatsapp, facebook and twitter.

AnkproTraining
Автор

Thanks a lot for such amazing lectures, actually I know java selenium, As my company need is now C# with selenium, I go through different sources, but after completing some of your lectures.I get confidence in writing code. Thanks a lot for such a great

arabindamohanty
Автор

Thank you so much....its very use full. Nice Explanation. once again thank you so much

sruthis
Автор

Very well explained.with examples Thank you

gayathrivr
welcome to shbcf.ru