0
0
Selenium Pythontesting~20 mins

pytest with Selenium setup in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Selenium pytest Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of pytest fixture with Selenium WebDriver
What will be the output when running this pytest test with the given fixture?
Selenium Python
import pytest
from selenium import webdriver

@pytest.fixture
async def driver():
    driver = webdriver.Firefox()
    yield driver
    driver.quit()

def test_title(driver):
    driver.get('https://example.com')
    assert 'Example Domain' in driver.title
    print('Test Passed')
ATest Passed printed and test passes
BSyntaxError due to async fixture
CTest Passed printed but test fails with AssertionError
DRuntimeError because driver.quit() is not called
Attempts:
2 left
💡 Hint
pytest fixtures should not be async unless using pytest-asyncio plugin
assertion
intermediate
1:30remaining
Correct assertion for page title in Selenium test
Which assertion correctly verifies the page title contains 'Welcome' in a Selenium test using pytest?
Selenium Python
def test_page_title(driver):
    driver.get('https://mysite.com')
    # Choose the correct assertion below
Aassert driver.title == 'Welcome to MySite'
Bassert driver.title.index('Welcome') >= 0
Cassert driver.title.contains('Welcome')
Dassert 'Welcome' in driver.title
Attempts:
2 left
💡 Hint
Use Python's 'in' keyword to check substring presence
locator
advanced
2:00remaining
Best locator strategy for a button with dynamic ID
You want to locate a button with a dynamic ID that changes every page load but has a stable class 'submit-btn' and visible text 'Submit'. Which locator is best for Selenium?
Adriver.find_element('id', 'btn12345')
Bdriver.find_element('css selector', 'button.submit-btn')
Cdriver.find_element('xpath', "//button[contains(text(),'Submit') and contains(@class,'submit-btn')]")
Ddriver.find_element('name', 'submit')
Attempts:
2 left
💡 Hint
Use XPath to combine text and class attributes for stable selection
🔧 Debug
advanced
2:30remaining
Identify the cause of flaky Selenium test failure
This pytest Selenium test intermittently fails with NoSuchElementException. What is the most likely cause?
Selenium Python
def test_login(driver):
    driver.get('https://mysite.com/login')
    driver.find_element('id', 'username').send_keys('user')
    driver.find_element('id', 'password').send_keys('pass')
    driver.find_element('id', 'submit').click()
    assert 'Dashboard' in driver.title
AThe test runs too fast before page elements load; needs explicit wait
BThe element IDs are incorrect and do not exist on the page
CThe assertion is wrong; 'Dashboard' is not in the title
Ddriver.quit() is missing causing stale element errors
Attempts:
2 left
💡 Hint
Web pages may take time to load elements; Selenium needs waits
framework
expert
2:00remaining
pytest Selenium parallel test execution setup
Which pytest command correctly runs Selenium tests in parallel across 4 browser instances using pytest-xdist?
Apytest -n 4 --browser=firefox
Bpytest --parallel=4 --browser=firefox
Cpytest -n 4 --driver=firefox
Dpytest --workers=4 --driver=firefox
Attempts:
2 left
💡 Hint
pytest-xdist uses -n option to specify number of parallel workers