0
0
Selenium Pythontesting~10 mins

Getting element attributes 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 get the value of the "href" attribute from the link element.

Selenium Python
link = driver.find_element(By.ID, "home-link")
href_value = link.get_attribute([1])
print(href_value)
Drag options to blanks, or click blank then click option'
A"href"
B"text"
C"class"
D"id"
Attempts:
3 left
💡 Hint
Common Mistakes
Using attribute names like "text" or "class" instead of "href".
2fill in blank
medium

Complete the code to check if the "disabled" attribute is present on the button element.

Selenium Python
button = driver.find_element(By.CSS_SELECTOR, ".submit-btn")
disabled_attr = button.get_attribute([1])
if disabled_attr:
    print("Button is disabled")
else:
    print("Button is enabled")
Drag options to blanks, or click blank then click option'
A"checked"
B"enabled"
C"disabled"
D"readonly"
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for "enabled" attribute which does not exist.
3fill in blank
hard

Fix the error in the code to correctly get the "placeholder" attribute from the input element.

Selenium Python
input_box = driver.find_element(By.NAME, "email")
placeholder_text = input_box.get_attribute([1])
print(placeholder_text)
Drag options to blanks, or click blank then click option'
Aplaceholder
Bplaceholder_text
C'placeholder'
D"placeholder"
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the attribute name.
4fill in blank
hard

Fill both blanks to create a dictionary of element IDs and their "title" attributes for all elements with class "item".

Selenium Python
elements = driver.find_elements(By.CLASS_NAME, "item")
titles = {element.get_attribute([1]): element.get_attribute([2]) for element in elements}
print(titles)
Drag options to blanks, or click blank then click option'
A"id"
B"class"
C"title"
D"name"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "class" instead of "id" for keys.
Using wrong attribute for titles.
5fill in blank
hard

Fill all three blanks to filter elements with a "data-status" attribute equal to "active" and create a list of their "name" attributes.

Selenium Python
elements = driver.find_elements(By.TAG_NAME, "div")
active_names = [element.get_attribute([1]) for element in elements if element.get_attribute([2]) == [3]]
print(active_names)
Drag options to blanks, or click blank then click option'
A"name"
B"data-status"
C"active"
D"status"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names or missing quotes around "active".