0
0
Selenium Javatesting~5 mins

@FindBy annotations in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
A@FindBy(className = "btn")
B@FindBy(text = "username")
C@FindBy(id = "username")
D@FindBy(tag = "input")
What type of variable should be annotated with @FindBy?
AList<String>
BString
Cint
DWebElement
Which annotation allows combining multiple @FindBy annotations with AND logic?
A@FindAll
B@FindBys
C@FindByMultiple
D@FindByGroup
If you want to locate elements by CSS selector using @FindBy, which attribute do you use?
AcssSelector
Bcss
Cstyle
Dselector
What is the main advantage of using @FindBy in Page Object Model?
AIt separates element locators from test logic
BIt makes tests run faster
CIt automatically waits for elements
DIt replaces the need for assertions
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.