0
0
Selenium Pythontesting~20 mins

CSS selector syntax in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSS Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
selector
intermediate
2:00remaining
Identify the element selected by this CSS selector
Given the HTML snippet:
<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?
AThe &lt;div&gt; element with class 'container'
BThe &lt;ul&gt; element inside the container
CThe &lt;li&gt; element with text 'Home'
DAll &lt;li&gt; elements with class 'item'
Attempts:
2 left
💡 Hint
Look for the element with class 'active' inside the container's list items.
selector
intermediate
2:00remaining
Which CSS selector matches all direct child paragraphs?
Consider this HTML:
<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>?
Adiv p
Bdiv ~ p
Cdiv + p
Ddiv > p
Attempts:
2 left
💡 Hint
The '>' symbol means direct child in CSS selectors.
selector
advanced
2:00remaining
What is the output of this CSS selector in Selenium?
Given this HTML:
<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?
AThe &lt;li&gt; element with text 'Two'
BAll &lt;li&gt; elements with class 'item'
CThe &lt;li&gt; element with id 'first'
DNo elements will be selected
Attempts:
2 left
💡 Hint
Look for elements with both classes 'item' and 'special'.
selector
advanced
2:00remaining
Which CSS selector will select the last child element?
Given this HTML:
<div>
  <p>First</p>
  <p>Second</p>
  <p>Third</p>
</div>

Which CSS selector will select only the last <p> element inside the <div>?
Adiv p:last-of-type
Bdiv p:last-child
Cdiv p:nth-child(3)
Ddiv p:nth-last-child(1)
Attempts:
2 left
💡 Hint
The ':last-child' pseudo-class selects the last child of its parent.
selector
expert
2:00remaining
What error occurs with this invalid CSS selector in Selenium?
Consider this CSS selector used in Selenium:
div#main > ul li:first-child::before

What error will Selenium raise when trying to find elements with this selector?
ANoSuchElementException because no matching elements exist
BInvalidSelectorException due to unsupported pseudo-element '::before'
CTimeoutException due to slow page load
DStaleElementReferenceException because element changed
Attempts:
2 left
💡 Hint
Selenium does not support pseudo-elements like '::before' in CSS selectors.