Recall & Review
beginner
What is the purpose of the
@FindBy annotation in Selenium?The
@FindBy annotation is used to locate web elements on a page in Selenium's Page Object Model. It helps to define how to find elements using locators like id, name, xpath, cssSelector, etc.Click to reveal answer
beginner
How do you use
@FindBy to locate an element by its ID?You use
@FindBy(id = "elementId") before a WebElement field to tell Selenium to find the element with that ID.Click to reveal answer
intermediate
Can
@FindBy use multiple locator strategies together? If yes, how?Yes, by using
@FindBys or @FindAll annotations to combine multiple @FindBy annotations for AND or OR conditions respectively.Click to reveal answer
beginner
What happens if Selenium cannot find an element defined with
@FindBy during test execution?Selenium throws a
NoSuchElementException when it tries to interact with the element and cannot find it on the page.Click to reveal answer
beginner
Why is using
@FindBy considered better than using driver.findElement() directly in tests?Using
@FindBy supports the Page Object Model, making tests cleaner, easier to maintain, and separating element locators from test logic.Click to reveal answer
Which of the following is a valid way to locate an element using
@FindBy?✗ Incorrect
The correct locator attribute is 'id'. 'text' and 'tag' are not valid attributes for @FindBy. The correct attribute for class is 'className' (case sensitive).
What type of variable should be annotated with
@FindBy?✗ Incorrect
@FindBy is used to locate WebElement or List<WebElement> variables.Which annotation allows combining multiple
@FindBy annotations with AND logic?✗ Incorrect
@FindBys combines multiple @FindBy annotations with AND logic.If you want to locate elements by CSS selector using
@FindBy, which attribute do you use?✗ Incorrect
The correct attribute is
cssSelector.What is the main advantage of using
@FindBy in Page Object Model?✗ Incorrect
@FindBy helps separate element locators from test logic, improving code organization and maintainability.Explain how to use the
@FindBy annotation to locate a button by its CSS class and why this is useful in test automation.Think about how you tell Selenium where to find the element and how it helps keep tests clean.
You got /3 concepts.
Describe what happens when Selenium cannot find an element defined with
@FindBy during test execution and how you might handle it.Consider what Selenium does when it looks for an element that is missing and how to make tests more reliable.
You got /3 concepts.