Friday, December 23, 2016

Lesson #8 - Type of Locators available in the Selenium WebDriver API

Overview

Selenium WebDriver API, provides two functions that we can use for locating Web Elements, each function is used for a different purpose, as follows:

The FindElement () function is used when we need to work with a single web element, when executing this function; it will return a single object (Based on the search criteria) or throws up an exception.

The FindElements () function is used to retrieve more than a single element (Collection of elements).

תוצאת תמונה עבור ‪locators in selenium webdriver‬‏

Type of Locators


Locator Name
Code syntax (C# )
Description
ID
driver.FindElement(By.Id("Element ID"));
Locates an element using his ID
Name
driver.FindElement(By.Name("Element Name"));
Locates an element using his Name
Link text
driver.FindElement(By.LinkText ("Element link text"));
Locates an element using his Link Text
Class Name
driver.FindElement(By.ClassName("Element class name "));
Locates an element using his class name
Tag Name
driver.FindElement(By.TagName("Element Tag name"));
Locates an element using his tag name
CSS
driver.FindElement (By.CssSelector("Element CssSelector"));
Locates an element using CSS
XPath
driver.FindElement(By.XPath("Element XPath"));
Locates an element using XPath query
Partial Link text
driver.FindElement(By.PartialLinkText("Element PartialLinkText"));
Locates an element using a partial link text

No comments:

Post a Comment

My Presentations