0
0
Selenium Pythontesting~10 mins

Find element by CSS selector 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 find an element by its CSS selector.

Selenium Python
element = driver.find_element_by_css_selector([1])
Drag options to blanks, or click blank then click option'
A"#submit-button"
B"submit button"
C".submit-button"
D"submit-button"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to add '#' before the id in the selector.
Using a class selector '.' instead of id selector '#'.
2fill in blank
medium

Complete the code to find an element with class 'menu-item' using CSS selector.

Selenium Python
element = driver.find_element_by_css_selector([1])
Drag options to blanks, or click blank then click option'
A"menu item"
B"#menu-item"
C"menu-item"
D".menu-item"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name without '.' prefix.
Using '#' which is for id selectors.
3fill in blank
hard

Fix the error in the code to find an element by CSS selector for a button with class 'btn-primary'.

Selenium Python
element = driver.find_element_by_css_selector([1])
Drag options to blanks, or click blank then click option'
A".btn-primary"
B"btn-primary"
C"#btn-primary"
D"button.btn-primary"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name without '.' prefix.
Using id selector '#' instead of class selector '.'
4fill in blank
hard

Fill both blanks to find an input element with type 'text' using CSS selector.

Selenium Python
element = driver.find_element_by_css_selector("input[[1]='[2]']")
Drag options to blanks, or click blank then click option'
Atype
Btext
Cusername
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping attribute name and value.
Using 'name' instead of 'type' for the first blank.
5fill in blank
hard

Fill all three blanks to find a button element with class 'btn' and text 'Submit' using CSS selector.

Selenium Python
element = driver.find_element_by_css_selector("button.[1]:contains('[2]')")  # Note: :contains is not standard CSS
# Alternative: find by class and then check text separately
button = driver.find_element_by_css_selector("button.[3]")
Drag options to blanks, or click blank then click option'
Abtn
BSubmit
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class name without '.' prefix.
Trying to use :contains which is not supported in Selenium CSS selectors.