Page Object Model(POM) Interview Questions (2024)
What is Page Object Model(POM)?
What are the advantages of Page Object Model?
What is Page Factory in Selenium?
Why to use
@FindBy
in Page Object Model(POM)?What are locators in Selenium WebDriver used in Page Object Model(POM)?
What is initElements function in Page Object Model(POM)?
How page factory handles lazy initialization in Page Object Model(POM)?
What is the difference between Page Object Model (POM) and Page Factory?
Why raise function is used in exception handling in Page Object Model(POM)?
How can we retrieve the list of element in a Pagefactory of Page Object Model?
Can we use TestNG with Page object model?
Is it possible to create Page Object Model (POM) classes without a constructor?
Q: What is Page Object Model(POM)?
Ans:
The Selenium design pattern known as Page Object Model, or POM, creates an object repository for storing all web elements. It helps maintain test cases better and minimizes code duplication.
Q: What are the advantages of Page Object Model?
Ans:
Some of the important features of Page Object Model(POM) are listed below:
- Easy to maintain: POM is helpful and makes maintenance simple, when an action or UI element is modified.
- Code reuse: Code reuse is made easier by POM, which enables the use of test code for one screen in another test case.
- Scripts readability: By allowing programmers to decouple operations and UI flows from validation, it improves code readability.
Q: What is Page Factory in Selenium?
Ans:
Selenium WebDriver offers a class called Page Factory that supports inbuilt Page
Object Model framework design pattern. Testers utilize the @FindBy
annotation in
Page Factory.
Web elements are initialized using the initElements
function.
Q: Why to use @FindBy
in Page Object Model(POM)?
Ans:
Page Factory uses the annotation @FindBy
to identify and declare web items using
various locators.
@FindBy(id="componentId") WebElement component;
Take a look at our suggested post :
Q: What are locators in Selenium WebDriver used in Page Object Model(POM)?
Ans:
Locators are used to locate HTML elements on web pages. They let testers choose which HTML DOM element to work with.
In Selenium WebDriver, several locators are available.
- CSS ID -
find_element_by_id
- Attribute Name -
find_element_by_name
- ClassName -
find_element_by_class_name
- PartialLinkText -
find_element_by_partial_link_text
- Tag Name -
find_element_by_tag_name
- Xpath -
find_element_by_xpath
- LinkText -
find_element_by_link_text
from selenium import webdriver
driver = webdriver.Chrome('./chromedriver')
driver.get("https://www.techgeeknext.com")
//using CSS ID locator
component = driver.find_element_by_id("header-comp-id")
Q: What is initElements function in Page Object Model(POM)?
Ans:
A static method in the Page Factory class is called initElements
.
One can
initialize each web element found by the @FindBy
annotation using the initElements
function.
Q: How page factory handles lazy initialization in Page Object Model(POM)?
Ans:
The Page Factory concept of AjaxElementLocatorFactory
uses lazy loading. This only
helps to
identify web elements when they are included into a process or activity. With the use of the
AjaxElementLocatorFactory
, the timeout of a web element can be specified to the
object class.
Q: What is the difference between Page Object Model (POM) and Page Factory?
Ans:
A web page is represented by a page object model, which contains its functionality and members. When we create an instance of the page object, we can use Page Factory to initialize the web components to interact with. The implementation of the Page Object Model design pattern is provided by PageFactory. Also lazy initialization can handle using PageFactory.
Q: Will the program run if intiElements() is not used in the Page Object Model (POM)?
Ans:
No, the code won't execute and will throw a NullPointerException
.
Q: How can we retrieve the list of element in a Pagefactory of Page Object Model?
Ans:
We can retrieve the list of element in a Pagefactory using the @FindAllBy
annotation.
@FindAllBy(xpath = "//*[contains(......)]")
List<WebElement> allPageElements;
Q: Can we use TestNG with Page Object Model?
Ans:
Yes, create methods for the Page Objects which indicates the actions that needs to be executed in page. Create tests that execute these actions in the specified order. Run the tests using TestNG, then examine the outcomes.
Q: Is it possible to create Page Object Model (POM) classes without a constructor?
Ans:
Yes, could be possible by making use of initElements()
.