0
0
Selenium Pythontesting~10 mins

Test functions and classes 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 define a test function using pytest.

Selenium Python
def [1]():
    assert 2 + 2 == 4
Drag options to blanks, or click blank then click option'
Aaddition_test
Btest_addition
Ccheck_add
Dverify_sum
Attempts:
3 left
💡 Hint
Common Mistakes
Naming the function without 'test_' prefix so pytest ignores it.
Using spaces or special characters in the function name.
2fill in blank
medium

Complete the code to import the Selenium WebDriver for Chrome.

Selenium Python
from selenium.webdriver import [1]
Drag options to blanks, or click blank then click option'
AChrome
BFirefox
CEdge
DSafari
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Firefox or other browsers when Chrome is needed.
Misspelling the browser name.
3fill in blank
hard

Fix the error in the test class definition for pytest.

Selenium Python
class [1]:
    def test_example(self):
        assert True
Drag options to blanks, or click blank then click option'
ATestExample
BExampleTest
CexampleTest
Dtestexample
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or names not starting with 'Test' for test classes.
Forgetting to capitalize the class name properly.
4fill in blank
hard

Fill both blanks to create a Selenium test that opens a page and checks the title.

Selenium Python
from selenium import webdriver

class TestPageTitle:
    def test_title(self):
        driver = webdriver.[1]()
        driver.get('https://example.com')
        assert driver.title [2] 'Example Domain'
        driver.quit()
Drag options to blanks, or click blank then click option'
AChrome
B==
C!=
DFirefox
Attempts:
3 left
💡 Hint
Common Mistakes
Using Firefox WebDriver when Chrome is intended.
Using '!=' instead of '==' in the assertion.
5fill in blank
hard

Fill all three blanks to create a pytest test function that finds an element by ID and asserts its text.

Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import [1]

def test_element_text():
    driver = webdriver.Chrome()
    driver.get('https://example.com')
    element = driver.find_element([2], 'example-id')
    assert element.text [3] 'Example Domain'
    driver.quit()
Drag options to blanks, or click blank then click option'
ABy
BBy.ID
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Not importing 'By' and trying to use it directly.
Using wrong locator like 'By.NAME' instead of 'By.ID'.
Using '!=' instead of '==' in assertion.