0
0
Selenium Pythontesting~10 mins

CSS pseudo-classes for selection in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select the first child element using CSS pseudo-class.

Selenium Python
element = driver.find_element(By.CSS_SELECTOR, 'ul li[1]')
Drag options to blanks, or click blank then click option'
A:first-child
B:last-child
C:nth-child(2)
D:hover
Attempts:
3 left
💡 Hint
Common Mistakes
Using :last-child instead of :first-child
Using :hover which is for mouse actions
2fill in blank
medium

Complete the code to select all even child elements using CSS pseudo-class.

Selenium Python
elements = driver.find_elements(By.CSS_SELECTOR, 'div.item[1]')
Drag options to blanks, or click blank then click option'
A:odd
B:first-of-type
C:nth-child(even)
D:last-of-type
Attempts:
3 left
💡 Hint
Common Mistakes
Using :odd instead of :nth-child(even)
Using :first-of-type which selects only the first element
3fill in blank
hard

Fix the error in the code to select the last child element using CSS pseudo-class.

Selenium Python
element = driver.find_element(By.CSS_SELECTOR, 'table tr[1]')
Drag options to blanks, or click blank then click option'
A:first-child
B:lastchild
C:nth-last-child(1)
D:last-child
Attempts:
3 left
💡 Hint
Common Mistakes
Missing hyphen in :last-child
Using :first-child instead of last-child
4fill in blank
hard

Fill both blanks to select every 3rd child starting from the first using CSS pseudo-class.

Selenium Python
elements = driver.find_elements(By.CSS_SELECTOR, 'ul li[1]([2])')
Drag options to blanks, or click blank then click option'
A:nth-child
B3n+1
C2n
D:nth-of-type
Attempts:
3 left
💡 Hint
Common Mistakes
Using :nth-of-type instead of :nth-child
Using 2n instead of 3n+1
5fill in blank
hard

Fill all three blanks to select all list items except the first and last using CSS pseudo-classes.

Selenium Python
elements = driver.find_elements(By.CSS_SELECTOR, 'ul li:not([1]):not([2])[3]')
Drag options to blanks, or click blank then click option'
A:first-child
B:last-child
C:hover
D:nth-child(n)
Attempts:
3 left
💡 Hint
Common Mistakes
Using :hover which is unrelated
Not excluding both first and last children