0
0
Selenium Pythontesting~20 mins

Parameterized tests in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Parameterized Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of parameterized Selenium test with multiple inputs
Consider this parameterized Selenium test using pytest. What will be the output when running this test suite?
Selenium Python
import pytest
from selenium.webdriver.common.by import By

@pytest.mark.parametrize('search_term', ['apple', 'banana'])
def test_search(browser, search_term):
    browser.get('https://example.com')
    search_box = browser.find_element(By.NAME, 'q')
    search_box.send_keys(search_term)
    search_box.submit()
    assert search_term in browser.title
ABoth tests pass if page title contains 'apple' and 'banana' respectively
BTests run but assertion always fails due to wrong locator
CBoth tests fail because 'browser' fixture is not defined
DOnly the first test runs because parameterization is incorrect
Attempts:
2 left
💡 Hint
Think about what is missing for the test to run properly with Selenium.
assertion
intermediate
2:00remaining
Correct assertion in parameterized test for form validation
You have a parameterized test that submits a form with different inputs. Which assertion correctly verifies that the error message appears when input is invalid?
Selenium Python
import pytest
from selenium.webdriver.common.by import By

@pytest.mark.parametrize('input_value, expect_error', [('', True), ('valid', False)])
def test_form_validation(browser, input_value, expect_error):
    browser.get('https://example.com/form')
    input_field = browser.find_element(By.ID, 'input')
    input_field.clear()
    input_field.send_keys(input_value)
    submit_button = browser.find_element(By.ID, 'submit')
    submit_button.click()
    error_elements = browser.find_elements(By.CLASS_NAME, 'error')
    # Which assertion is correct?
Aassert (len(error_elements) > 0) == expect_error
Bassert error_elements.text == expect_error
Cassert error_elements.is_displayed() == expect_error
Dassert error_elements.exists() == expect_error
Attempts:
2 left
💡 Hint
Remember that find_elements returns a list, not a single element.
locator
advanced
2:00remaining
Best locator strategy for parameterized test with dynamic IDs
In a parameterized test, you need to locate a button whose ID changes dynamically but always starts with 'btn_'. Which locator is best to use?
ABy.CLASS_NAME, 'btn_'
BBy.ID, 'btn_' + dynamic_part
CBy.XPATH, '//button[contains(@id, "btn_")]'
DBy.CSS_SELECTOR, 'button[id^="btn_"]'
Attempts:
2 left
💡 Hint
Look for a locator that matches the start of the ID attribute.
🔧 Debug
advanced
2:00remaining
Debugging flaky parameterized Selenium test
A parameterized Selenium test intermittently fails with 'ElementNotInteractableException' on clicking a button. What is the most likely cause?
Selenium Python
import pytest
from selenium.webdriver.common.by import By

@pytest.mark.parametrize('page', ['home', 'about'])
def test_click_button(browser, page):
    browser.get(f'https://example.com/{page}')
    button = browser.find_element(By.ID, 'start')
    button.click()
    assert 'Started' in browser.page_source
AThe parameterization syntax is invalid causing test failure
BThe button is not visible or ready when click is attempted
CThe locator ID 'start' is incorrect on some pages
DThe assertion is wrong and causes false failures
Attempts:
2 left
💡 Hint
Consider timing and element readiness in Selenium tests.
framework
expert
3:00remaining
Implementing parameterized tests with pytest and Selenium for multiple browsers
You want to run the same parameterized test on Chrome and Firefox browsers using pytest and Selenium. Which pytest fixture setup correctly supports this?
AUse @pytest.mark.parametrize('browser_name', ['chrome', 'firefox']) and a fixture that initializes WebDriver based on browser_name
BCreate separate test functions for each browser without parameterization
CUse a global variable to switch browsers inside the test
DUse Selenium Grid without any pytest parameterization
Attempts:
2 left
💡 Hint
Think about combining pytest parameterization with fixtures for browser setup.