0
0
Selenium Pythontesting~10 mins

Page factory pattern in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the PageFactory class from selenium.

Selenium Python
from selenium.webdriver.support.[1] import PageFactory
Drag options to blanks, or click blank then click option'
Apage_factory
Bpagefactory
CPageFactory
DPagefactory
Attempts:
3 left
💡 Hint
Common Mistakes
Using underscore or incorrect casing in the submodule name.
Trying to import PageFactory directly without submodule.
2fill in blank
medium

Complete the code to initialize page elements using PageFactory.

Selenium Python
PageFactory.[1](driver, self)
Drag options to blanks, or click blank then click option'
AinitElements
Binitialize_elements
Cinit_elements
DinitializeElements
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase method names which do not exist in Python.
Misspelling the method name.
3fill in blank
hard

Fix the error in the locator declaration for a button element.

Selenium Python
submit_button = driver.find_element(By.[1], "submit")
Drag options to blanks, or click blank then click option'
AXPATH
BNAME
CCLASS_NAME
DID
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase locators (must be ID, not id).
Choosing wrong locator type like XPATH for simple id.
Using deprecated find_element_by_* methods.
4fill in blank
hard

Fill both blanks to declare a page element locator tuple for the PageFactory pattern.

Selenium Python
from selenium.webdriver.common.by import By

class LoginPage:
    username = (By.[1], [2])
Drag options to blanks, or click blank then click option'
AID
BNAME
C"username_field"
D"[name='username']"
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting double quotes around the selector value.
Using lowercase locator strategy (ID not id).
Wrong locator strategy or selector.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps element names to their text if visible.

Selenium Python
elements_text = {name: element.text for name, element in [1].items() if element.is_[2]() and element.text [3] ''}
Drag options to blanks, or click blank then click option'
A!=
Bdisplayed
Cself.elements
Dvisible
Eelements
Fis_displayed
G==
His_visible
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method name for visibility check.
Using equality operator instead of inequality.
Using wrong variable name for elements.