Locating Web Elements

For working with the elements that are available on the web page. We need to inspect them uniquely then only we will be able to work and operate on these elements.
In Selenium, We can locate/inspect the element in different ways. As shown below
1) Inspect the element by its Name
2) Inspect the element by its ID
3) Inspect the element by its xPath
4) Inspect the element by its CSS
5) Inspect the element by its ClassName
6) Inspect the element by its LinkText
7) Inspect the element by its Partial LinkText
9) Inspect the element by its Tag Name

Methods provided by Selenium for these elements are available in Selenium’s By Class
1) By.name(“Name of the element “);
2) By.id(“ID of the element”);
3) By.xPath(“xPath of the element”);
4) By.cssSelector(“css of the element “);
5) By.LinkText(“Link text of the element”);
6) By.PartialLinkText(“partial link Text of the element”);
7) By.className(“class Name of the element”);
8) By.tagName(“Tag Name of the element”);

How to Inspect the element ?
– Right click on the element and click on the context menu. Will get an option i.e Inspect. By Click on the Inspect Option it will open the page source. Then just right click on the selected code for copying its Xpath. As shown below

Design a site like this with WordPress.com
Get started