0
0
Selenium Pythontesting~20 mins

Opening URLs (get) in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
URL Opening Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Selenium code snippet?
Consider the following Python Selenium code that opens a URL and prints the current URL.
What will be printed?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
service = Service()
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://example.com')
print(driver.current_url)
driver.quit()
Aabout:blank
Bhttps://example.com
Chttps://example.com/
DRaises NoSuchWindowException
Attempts:
2 left
💡 Hint
The browser normalizes URLs and often adds a trailing slash for root domains.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the page title after opening a URL?
You want to check that after opening 'https://example.com', the page title is exactly 'Example Domain'. Which assertion is correct?
Selenium Python
driver.get('https://example.com')
# Which assertion below is correct?
Aassert driver.title = 'Example Domain'
Bassert driver.title == 'Example Domain'
Cassert driver.title != 'Example Domain'
Dassert driver.title.contains('Example Domain')
Attempts:
2 left
💡 Hint
Use '==' to compare values in Python assertions.
locator
advanced
1:30remaining
Which locator is best to find the main heading after opening a URL?
After opening 'https://example.com', you want to locate the main heading <h1> element. Which locator is best practice?
Selenium Python
driver.get('https://example.com')
# Choose the best locator to find the main heading
Adriver.find_element('tag name', 'h1')
Bdriver.find_element('css selector', 'div > h1')
Cdriver.find_element('xpath', '//div/h1')
Ddriver.find_element('id', 'main-heading')
Attempts:
2 left
💡 Hint
Use simple and direct locators when possible.
🔧 Debug
advanced
2:00remaining
Why does this Selenium code raise an error when opening a URL?
Examine the code below. It raises an error when trying to open the URL. What is the cause?
Selenium Python
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('htp://example.com')
driver.quit()
AThe URL scheme 'htp' is invalid, causing a WebDriverException
BThe Chrome driver is not initialized properly
Cdriver.quit() is called too early
Ddriver.get() requires a file path, not a URL
Attempts:
2 left
💡 Hint
Check the URL spelling carefully.
framework
expert
3:00remaining
In a pytest Selenium test, which fixture setup ensures the browser opens the URL before each test?
You want to write a pytest fixture that opens 'https://example.com' before each test and closes the browser after. Which fixture code is correct?
A
import pytest
from selenium import webdriver

@pytest.fixture
async def driver():
    driver = webdriver.Chrome()
    driver.get('https://example.com')
    yield driver
    driver.quit()
B
import pytest
from selenium import webdriver

@pytest.fixture

def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()
C
import pytest
from selenium import webdriver

@pytest.fixture
async def driver():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()
D
import pytest
from selenium import webdriver

@pytest.fixture

def driver():
    driver = webdriver.Chrome()
    driver.get('https://example.com')
    yield driver
    driver.quit()
Attempts:
2 left
💡 Hint
Pytest fixtures are usually synchronous unless using async tests.