0
0
Selenium Pythontesting~10 mins

Test class using page objects 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 Selenium WebDriver module.

Selenium Python
from selenium import [1]
Drag options to blanks, or click blank then click option'
Awebdriver
Bwebdriver_manager
Cselenium
Dwebdriver_remote
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'selenium' directly instead of 'webdriver'
Using 'webdriver_manager' which is a separate package
Misspelling 'webdriver'
2fill in blank
medium

Complete the code to initialize the Chrome WebDriver in the test setup method.

Selenium Python
def setup_method(self):
    self.driver = [1]()
Drag options to blanks, or click blank then click option'
Awebdriver.Safari
Bwebdriver.Chrome
Cwebdriver.Edge
Dwebdriver.Firefox
Attempts:
3 left
💡 Hint
Common Mistakes
Using Firefox or Edge driver instead of Chrome
Forgetting parentheses after the driver class
Using lowercase 'chrome' instead of 'Chrome'
3fill in blank
hard

Fix the error in the test method to correctly assert the page title.

Selenium Python
def test_title(self):
    self.driver.get('https://example.com')
    assert self.driver.title [1] 'Example Domain'
Drag options to blanks, or click blank then click option'
A!=
B<
C==
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which checks for inequality
Using '<' or '>' which are not correct for string equality
Forgetting to compare the title at all
4fill in blank
hard

Fill both blanks to create a page object method that returns the login button element.

Selenium Python
def get_login_button(self):
    return self.driver.find_element([1], [2])
Drag options to blanks, or click blank then click option'
A"By.ID"
BBy.ID
C"login-button"
Dlogin-button
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around By.ID making it a string
Not using By.ID as locator strategy
Putting quotes around the locator variable name
5fill in blank
hard

Fill all three blanks to create a test method that uses the page object to click the login button and assert the URL.

Selenium Python
def test_login_button(self):
    page = LoginPage(self.driver)
    page.[1]()
    assert self.driver.current_url [2] 'https://example.com/dashboard'
    self.driver.[3]()
Drag options to blanks, or click blank then click option'
Aclick_login_button
B==
Cquit
Dopen_login_page
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names for clicking
Using '!=' or other operators instead of '==' for assertion
Using 'close()' instead of 'quit()' to close the browser