0
0
Selenium Javatesting~5 mins

PageFactory initialization in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is PageFactory in Selenium?
PageFactory is a class in Selenium that helps initialize web elements defined in a Page Object Model class, making tests easier to read and maintain.
Click to reveal answer
beginner
How do you initialize web elements using PageFactory in Java?
You call <code>PageFactory.initElements(driver, this);</code> inside the constructor of your page class to initialize all @FindBy annotated elements.
Click to reveal answer
beginner
What is the purpose of the @FindBy annotation?
It tells Selenium how to locate a web element on the page, such as by id, name, xpath, or css.
Click to reveal answer
intermediate
Why is PageFactory initialization preferred over traditional element locating?
PageFactory initializes elements only when they are used, improving performance and making the code cleaner and easier to maintain.
Click to reveal answer
beginner
What happens if you forget to call PageFactory.initElements() in your page class?
The web elements will not be initialized, causing NullPointerException when you try to interact with them.
Click to reveal answer
Which method is used to initialize web elements with PageFactory in Selenium Java?
AWebDriverWait.until();
Bdriver.findElement();
Cdriver.get();
DPageFactory.initElements(driver, this);
What annotation is used to locate elements in PageFactory?
A@FindBy
B@Locate
C@Element
D@WebElement
What will happen if you try to use a web element without initializing PageFactory?
ANullPointerException will occur.
BThe element will be found automatically.
CThe test will pass without issues.
DThe element will be ignored.
PageFactory initialization improves test code by:
AMaking tests slower
BMaking code harder to read
CInitializing elements lazily and improving readability
DRemoving the need for locators
Which of the following is NOT a valid locator strategy with @FindBy?
Aname
Bcolor
Cxpath
Did
Explain how PageFactory initialization works in Selenium and why it is useful.
Think about how PageFactory connects your page class fields to actual web elements.
You got /4 concepts.
    Describe the steps to create a Page Object class using PageFactory in Selenium Java.
    Focus on annotations, constructor, and usage.
    You got /3 concepts.