0
0
Selenium Pythontesting~10 mins

Why mastering selectors ensures reliability in Selenium Python - Test Your Understanding

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 ID using Selenium in Python.

Selenium Python
element = driver.find_element(By.[1], "submit-button")
Drag options to blanks, or click blank then click option'
ATAG_NAME
BID
CNAME
DCLASS_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using class_name instead of id when the element has a unique ID.
2fill in blank
medium

Complete the code to find all elements with a specific class name.

Selenium Python
elements = driver.find_elements(By.[1], "menu-item")
Drag options to blanks, or click blank then click option'
AID
BXPATH
CCSS_SELECTOR
DCLASS_NAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using find_element instead of find_elements when expecting multiple elements.
3fill in blank
hard

Fix the error in the selector to correctly find a button with text 'Submit'.

Selenium Python
button = driver.find_element(By.[1], "//button[text()='Submit']")
Drag options to blanks, or click blank then click option'
AXPATH
BCSS_SELECTOR
CID
DNAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using css_selector with XPath syntax causes errors.
4fill in blank
hard

Fill both blanks to create a reliable CSS selector for all buttons with class 'btn' inside a div with ID 'container'.

Selenium Python
buttons = driver.find_elements(By.[1], "div#[2] button.btn")
Drag options to blanks, or click blank then click option'
ACSS_SELECTOR
BXPATH
Ccontainer
Dsubmit
Attempts:
3 left
💡 Hint
Common Mistakes
Using XPath syntax inside a CSS selector.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps input names to their values for inputs inside a form with ID 'login'.

Selenium Python
inputs = driver.find_elements(By.[1], "form#login input")
values = {input.get_attribute([2]): input.get_attribute([3]) for input in inputs}
Drag options to blanks, or click blank then click option'
ACSS_SELECTOR
B"name"
C"value"
DXPATH
Attempts:
3 left
💡 Hint
Common Mistakes
Using XPath instead of CSS selector for inputs.
Mixing attribute names incorrectly.