Friday, August 23, 2024

By Class Locators MCQ

 Here are 20 multiple-choice questions (MCQs) focusing on different types of locators in Selenium, including Name, ID, Class, Link Text, Partial Link Text, Tag Name, XPath, and CSS Selector:



Which locator strategy is generally the fastest and most reliable to find elements in Selenium?

a) XPath

b) ID

c) Class Name

d) CSS Selector


Answer: b) ID


Which locator strategy would you use to locate an element using its HTML tag name?

a) By.xpath()

b) By.tagName()

c) By.className()

d) By.cssSelector()


Answer: b) By.tagName()


If you want to find a web element by its name attribute, which locator should you use?

a) By.id()

b) By.name()

c) By.className()

d) By.cssSelector()


Answer: b) By.name()


Which of the following locators would be best to use if you want to locate an element with a unique ID attribute?

a) By.name()

b) By.id()

c) By.tagName()

d) By.linkText()


Answer: b) By.id()


To locate a hyperlink text that says "Home", which locator strategy would you use?

a) By.linkText("Home")

b) By.partialLinkText("Home")

c) By.xpath("//a[contains(text(),'Home')]")

d) By.cssSelector("a[title='Home']")


Answer: a) By.linkText("Home")


Which locator strategy allows you to find a link element based on a substring of its text?

a) By.linkText()

b) By.partialLinkText()

c) By.xpath()

d) By.cssSelector()


Answer: b) By.partialLinkText()


Which Selenium locator strategy is best to use when selecting elements by their CSS class?

a) By.id()

b) By.tagName()

c) By.className()

d) By.name()


Answer: c) By.className()



Which locator strategy uses a combination of tag name, class, ID, or attributes to locate elements?

a) By.className()

b) By.xpath()

c) By.linkText()

d) By.tagName()


Answer: b) By.xpath()



If an element does not have an ID, name, or class, which locator would be the most flexible to use?

a) By.linkText()

b) By.cssSelector()

c) By.xpath()

d) By.tagName()

Answer: c) By.xpath()



No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...