0
0
Selenium Pythontesting~10 mins

Why POM organizes test code in Selenium Python - Test Your Understanding

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

Complete the code to import the Selenium WebDriver module.

Selenium Python
from selenium import [1]
Drag options to blanks, or click blank then click option'
Aseleniumbase
Bwebdriver_manager
Cwebdriver_remote
Dwebdriver
Attempts:
3 left
💡 Hint
Common Mistakes
Importing webdriver_manager instead of webdriver
Using wrong module names
2fill in blank
medium

Complete the code to define a Page Object class for the login page.

Selenium Python
class LoginPage:
    def __init__(self, driver):
        self.driver = [1]
Drag options to blanks, or click blank then click option'
Abrowser
Bsession
Cdriver
Dpage
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variable names
Assigning wrong parameter
3fill in blank
hard

Fix the error in the method that clicks the login button using a locator.

Selenium Python
def click_login(self):
    login_button = self.driver.find_element_by_[1]("loginBtn")
    login_button.click()
Drag options to blanks, or click blank then click option'
Aid
Bname
Cclass_name
Dxpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong locator methods like name or class_name
Typos in method names
4fill in blank
hard

Fill both blanks to create a method that enters username and password.

Selenium Python
def login(self, username, password):
    self.driver.find_element_by_[1]("username").send_keys(username)
    self.driver.find_element_by_[2]("password").send_keys(password)
Drag options to blanks, or click blank then click option'
Aid
Bname
Cclass_name
Dtag_name
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing locator types for username and password
Using class_name or tag_name incorrectly
5fill in blank
hard

Fill the two blanks to write a test that uses the LoginPage object to perform login and verify success.

Selenium Python
def test_login():
    driver = webdriver.Chrome()
    login_page = LoginPage(driver)
    driver.get("http://example.com/login")
    login_page.login([1], [2])
    login_page.click_login()
    assert "Dashboard" in driver.title
    driver.quit()
Drag options to blanks, or click blank then click option'
A"user1"
B"pass123"
C"admin"
D"password"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect argument types
Not quitting the driver after test