0
0
Selenium Pythontesting~10 mins

Page class structure 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
Cdriver
Dselenium
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'WebDriver' which is incorrect for import.
Importing 'driver' or 'selenium' which are not valid modules.
2fill in blank
medium

Complete the code to define the constructor method for the page class.

Selenium Python
class LoginPage:
    def [1](self, driver):
        self.driver = driver
Drag options to blanks, or click blank then click option'
A__del__
Bconstructor
C__init__
Dinit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'constructor' or 'init' without underscores.
Using '__del__' which is the destructor method.
3fill in blank
hard

Fix the error in the locator definition for the username field.

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

class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.username_input = (By.[1], "username")
Drag options to blanks, or click blank then click option'
Aname
BID
CName
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'id' or 'name' which are invalid in By.
Using 'Name' with uppercase N which is not defined.
4fill in blank
hard

Fill in the blank to define a method that clicks the login button.

Selenium Python
class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.login_button = (By.ID, "loginBtn")

    def click_login(self):
        self.driver.find_element([1]).click()
Drag options to blanks, or click blank then click option'
Aself.login_button
B*self.login_button
CBy.ID, "loginBtn"
Dself.loginBtn
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the locator tuple directly without unpacking.
Using incorrect attribute names like 'loginBtn'.
5fill in blank
hard

Fill all three blanks to complete a method that enters text into the username field.

Selenium Python
class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.username_input = (By.ID, "username")

    def enter_username(self, username):
        element = self.driver.find_element([1])
        element.[2]([3])
Drag options to blanks, or click blank then click option'
A*self.username_input
Bsend_keys
Cusername
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to unpack the locator tuple.
Using click instead of send_keys to enter text.
Passing the string 'username' instead of the variable.