0
0
Selenium Pythontesting~10 mins

Base page class 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'
Aselenium
BWebDriver
Cdriver
Dwebdriver
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 BasePage class constructor with a driver parameter.

Selenium Python
class BasePage:
    def __init__(self, [1]):
        self.driver = driver
Drag options to blanks, or click blank then click option'
Awebdriver
Bself
Cdriver
Dbrowser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'self' as a parameter which is reserved for instance reference.
Using 'browser' or 'webdriver' which are not used in this context.
3fill in blank
hard

Fix the error in the method to find an element by CSS selector.

Selenium Python
def find_element(self, css_selector):
    return self.driver.find_element_by_[1](css_selector)
Drag options to blanks, or click blank then click option'
Acss_selector
Bcss
CcssSelector
Dcssselector
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'css' which creates an invalid method name.
Using 'cssSelector' which is camel case.
Using 'cssselector' without the underscore.
4fill in blank
hard

Fill both blanks to create a method that waits for an element to be visible using WebDriverWait and expected_conditions.

Selenium Python
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def wait_for_element(self, locator):
    wait = WebDriverWait(self.driver, [1])
    return wait.until(EC.[2](locator))
Drag options to blanks, or click blank then click option'
A10
B5
Cvisibility_of_element_located
Dpresence_of_element_located
Attempts:
3 left
💡 Hint
Common Mistakes
Using too short wait time like 5 seconds which might be insufficient.
Using presence_of_element_located which does not guarantee visibility.
5fill in blank
hard

Fill all three blanks to create a method that clicks an element after waiting for it to be clickable.

Selenium Python
def click_element(self, locator):
    wait = WebDriverWait(self.driver, [1])
    element = wait.until(EC.[2](locator))
    element.[3]()
Drag options to blanks, or click blank then click option'
A15
Bclickable
Cclick
Delement_to_be_clickable
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'clickable' alone which is not a valid expected condition.
Calling 'clickable()' instead of 'click()' on the element.