Tuesday 7 November 2017

Locators In Selenium

FindElement and FindElements:
If you want to find any object or Element on the webpage we are going to use
1. ID
2. Class
3. TagName
4 .name
5. Xpath
6. CssSelector
7. LinkText
8. PartialLinktext
These 8 locators will be given by the HTML developers and will be there in html, when you run the code selenium Webdriver is going to search the HTML page for user desired object with any one of the above mentioned locators.
So in order to search a HTML page in selenium Webdriver we are going to use FindElement and FindElements methods.
Here we are going to see 3 important differences between FindElement and FindElements methods with this you can understand the mechanism easily




FindElement
FindElements
Difference #1
ReturnType
Webelement(Interface)
List(Java.util)
Parameters
By class method
By Class method
Difference #2
What happens if not able to find an object or element with specified locator
"NoSuchElementException" will be thrown
List will retunr 0 Elements (Do not thrown any exception)
Difference #3
Mechanism to Find the Object
This method will search HTML page and finds only the first object with specified locator(If there are multiple elements with the desired locator you have to identify the object uniquely)
This method will find all the elements with specified locator(if There are multiple elements then it is going to return group of elements as List you have to iterate through each element and you should find the desired element)

0 comments:

Post a Comment