Interview Questions on Locating Elements

Interview Questions on Locating Elements in Selenium, Inspection HTML elements, finding unique locators, and writing Selenium Test cases.

‘Selenium with Java’ Online Training 

An important task in Automated Functional Testing is ‘Object Identification’ or ‘Locating Elements’.

Functional Test tools like Micro Focus – UFT/QTP, IBM-RFT, SilkTest, SmartBear – TestComplete, Watir, etc, perform Test operations based on front-end objects.

Performance Test tools like Micro Focus – LoadRunner, IBM – RPT, Silk Performer, JMeter, NeoLoad, etc, perform test operations based on protocols.

Interview Questions on Locating Elements in Selenium

1. What is Web/HTML Element Locator?

It is an address that identifies a web element uniquely within a web page.

2. What are Element Locators in selenium?

Selenium supports eight locators, you can use any one of those locators to locate an element by Selenium.

1. id()
2. name()
3. className()
4. tagName()
5. linkText()
6. partialLinkText()
7. cssSelector()
8. xpath()

3. Why do we need multiple locators to locate web element in web pages?

Some locators are not applicable for all types of elements.
Ex: likText() and partialLinkText()

All locators may not visible for every element.

Some locators may be duplicated.

4. What are the tips on using Selectors/Locators?

In general, if HTML IDs are available, unique, and consistently predictable, they are the preferred method for locating an element on a page.

If unique IDs are unavailable, a well-written CSS selector is the preferred method of locating an element. XPath works as well as CSS selectors, but the syntax is complicated and frequently difficult to debug.

Selection strategies based on linkText and partialLinkText have drawbacks in that they only work on link elements.

Tag name can be a dangerous way to locate elements. There are frequently multiple elements of the same tag present on the page.

5. How to get unique locators for elements?

Follow Selenium tips on using Selectors.
Perform dry run and identify unique locators.

6. How to inspect Elements?

Using a web browser built-in feature (Google Chrome, Mozilla Firfox, MS Edge)
Firefox – Page Inspector
(* Three or Four years back plug-ins for browsers (Firebug and Firepath))

Chrome/Edge – Developer Tools (F12)

7. How to write Selenium Step?

Selenium Test Step:
//Locate an Element and Perform an Action on the element.

Syntax:

driverObject.findElement(By.ElementLocator/id(“value”)).Selenium WebDriver Command/Method();

8. What is Selenium WebElement?

It represents an HTML element. Generally, all interesting operations to do with interacting with a page will be performed through this interface.

WebElement Syntax:
//Create a WebElement by locating a web element.
WebElement name= driverObject.findElement(By.ElementLocator(“Value”));

//Perform 1st Action
WebElement_name.Selenium WebDriver Method();

//Perform 2nd Action o the same element
WebElement_name.Selenium WebDriver Method2();

Selenium Tutorial for Beginners.

Selenium Full Course (Selenium WebDriver, Java, TestNG, Automation Framework, and Project) Videos

Follow me on social media: