Challenge - 5 Problems
CSS Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate2:00remaining
Identify the element selected by this CSS selector
Given the HTML snippet:
Which element will be selected by the CSS selector
<div class="container">
<ul>
<li class="item active">Home</li>
<li class="item">About</li>
<li class="item">Contact</li>
</ul>
</div>Which element will be selected by the CSS selector
.container ul li.active?Attempts:
2 left
💡 Hint
Look for the element with class 'active' inside the container's list items.
✗ Incorrect
The selector '.container ul li.active' targets <li> elements with class 'active' inside a <ul> inside an element with class 'container'. Only the first <li> has class 'active', so it is selected.
❓ selector
intermediate2:00remaining
Which CSS selector matches all direct child paragraphs?
Consider this HTML:
Which CSS selector will select only the paragraphs that are direct children of the <div>?
<div>
<p>First paragraph</p>
<section>
<p>Nested paragraph</p>
</section>
</div>Which CSS selector will select only the paragraphs that are direct children of the <div>?
Attempts:
2 left
💡 Hint
The '>' symbol means direct child in CSS selectors.
✗ Incorrect
The selector 'div > p' selects only <p> elements that are direct children of <div>. 'div p' selects all descendants, including nested ones.
❓ selector
advanced2:00remaining
What is the output of this CSS selector in Selenium?
Given this HTML:
What element(s) will be selected by the CSS selector
<ul> <li id="first" class="item">One</li> <li class="item special">Two</li> <li class="item">Three</li> </ul>
What element(s) will be selected by the CSS selector
li.item.special in Selenium?Attempts:
2 left
💡 Hint
Look for elements with both classes 'item' and 'special'.
✗ Incorrect
The selector 'li.item.special' matches <li> elements that have both 'item' and 'special' classes. Only the second <li> matches.
❓ selector
advanced2:00remaining
Which CSS selector will select the last child element?
Given this HTML:
Which CSS selector will select only the last <p> element inside the <div>?
<div> <p>First</p> <p>Second</p> <p>Third</p> </div>
Which CSS selector will select only the last <p> element inside the <div>?
Attempts:
2 left
💡 Hint
The ':last-child' pseudo-class selects the last child of its parent.
✗ Incorrect
The selector 'div p:last-child' selects <p> elements that are the last child of their parent inside the div. The last <p> is the last child, so it is selected.
❓ selector
expert2:00remaining
What error occurs with this invalid CSS selector in Selenium?
Consider this CSS selector used in Selenium:
What error will Selenium raise when trying to find elements with this selector?
div#main > ul li:first-child::before
What error will Selenium raise when trying to find elements with this selector?
Attempts:
2 left
💡 Hint
Selenium does not support pseudo-elements like '::before' in CSS selectors.
✗ Incorrect
Selenium throws InvalidSelectorException when a CSS selector contains pseudo-elements like '::before' because they cannot be used to locate elements in the DOM.