0
0
Selenium Pythontesting~20 mins

Running tests on Grid in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Grid Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Selenium Grid test session initialization
What will be the output of this Selenium Python code snippet when connecting to a Selenium Grid hub?
Selenium Python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    options=options
)
driver.get('https://example.com')
title = driver.title
driver.quit()
print(title)
AExample Domain
Bselenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
Cselenium.common.exceptions.SessionNotCreatedException: Could not start a new session
Dselenium.common.exceptions.InvalidArgumentException: invalid argument: 'options' must be a dictionary
Attempts:
2 left
💡 Hint
Think about what the title of https://example.com is and what happens when the Remote WebDriver connects successfully.
assertion
intermediate
1:30remaining
Correct assertion for page title in Selenium Grid test
Which assertion correctly verifies that the page title is exactly 'Welcome Page' after loading a page using Selenium Grid in Python?
Selenium Python
driver.get('https://myapp.com/welcome')
page_title = driver.title
Aassert page_title == 'Welcome Page'
Bassert 'Welcome' in page_title
Cassert page_title.startswith('Welcome')
Dassert page_title != 'Welcome Page'
Attempts:
2 left
💡 Hint
The question asks for exact match, not partial or negation.
locator
advanced
1:30remaining
Best locator strategy for Selenium Grid test
You want to locate a login button with text 'Log In' on a page loaded via Selenium Grid. Which locator is the best practice for reliability and speed?
Adriver.find_element(By.XPATH, "//button[text()='Log In']")
Bdriver.find_element(By.CSS_SELECTOR, "button.login-btn")
Cdriver.find_element(By.CLASS_NAME, "btn-primary")
Ddriver.find_element(By.ID, "loginButton")
Attempts:
2 left
💡 Hint
IDs are unique and fastest locators if available.
🔧 Debug
advanced
2:00remaining
Identify the cause of session creation failure on Selenium Grid
Given this Python Selenium code connecting to a Grid, the test fails with 'SessionNotCreatedException'. What is the most likely cause?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')

driver = webdriver.Remote(
    command_executor='http://localhost:4444/wd/hub',
    options=options
)
driver.get('https://example.com')
AThe options argument is not supported by Remote WebDriver
BThe Selenium Grid hub is not running or unreachable at the given URL
CThe Chrome browser binary is missing on the node machine
DThe URL 'https://example.com' is invalid
Attempts:
2 left
💡 Hint
SessionNotCreatedException often means the browser could not start on the node.
framework
expert
2:30remaining
Parallel test execution strategy on Selenium Grid with pytest
You want to run 5 Selenium tests in parallel on a Selenium Grid using pytest. Which pytest command and configuration correctly achieves this?
Apytest --max-workers=5 --selenium-grid-url=http://localhost:4444/wd/hub
Bpytest -n 5 --dist=loadscope --maxfail=1
Cpytest -n 5 --dist=loadfile
Dpytest --parallel=5 --grid-url=http://localhost:4444
Attempts:
2 left
💡 Hint
pytest-xdist plugin uses -n to specify number of parallel workers.