0
0
Selenium Pythontesting~20 mins

CSS attribute selectors in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Attribute Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
locator
intermediate
1:30remaining
Identify the correct CSS attribute selector for exact match
Which CSS selector correctly locates an input element with the attribute type exactly equal to email?
Ainput[type*='email']
Binput[type^='email']
Cinput[type='email']
Dinput[type$='email']
Attempts:
2 left
💡 Hint
Remember, the exact match selector uses = inside the brackets.
assertion
intermediate
1:30remaining
Assertion for element presence using CSS attribute selector
Given the Selenium Python code below, which assertion correctly verifies that an element with data-test='submit-btn' is present on the page?
Selenium Python
element = driver.find_element(By.CSS_SELECTOR, "button[data-test='submit-btn']")
Aassert element.is_displayed()
Bassert element.text == 'submit-btn'
Cassert element.get_attribute('data-test') == 'button'
Dassert element.tag_name == 'input'
Attempts:
2 left
💡 Hint
Check if the element is visible rather than its text or tag.
Predict Output
advanced
1:30remaining
Output of Selenium find_elements with CSS attribute selector
What is the output type of the following Selenium Python code snippet?
Selenium Python
elements = driver.find_elements(By.CSS_SELECTOR, "input[name^='user']")
print(type(elements))
A<class 'WebElement'>
B<class 'list'>
C<class 'tuple'>
D<class 'dict'>
Attempts:
2 left
💡 Hint
find_elements returns multiple matches, not a single element.
🔧 Debug
advanced
2:00remaining
Identify the error in CSS attribute selector usage
What error will the following Selenium Python code raise?
Selenium Python
element = driver.find_element(By.CSS_SELECTOR, "input[name='user"]")
Aselenium.common.exceptions.NoSuchElementException
BTypeError
CSyntaxError
Dselenium.common.exceptions.InvalidSelectorException
Attempts:
2 left
💡 Hint
Check the quotes inside the CSS selector string.
🧠 Conceptual
expert
2:00remaining
Choosing the best CSS attribute selector for partial attribute matching
You want to select all input elements whose id attribute contains the substring email anywhere inside it. Which CSS selector should you use?
Ainput[id*='email']
Binput[id$='email']
Cinput[id^='email']
Dinput[id='email']
Attempts:
2 left
💡 Hint
Look for the selector that matches substring anywhere, not just start or end.