Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the correct Selenium class for drag and drop.
Selenium Python
from selenium.webdriver import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing By or Keys instead of ActionChains.
✗ Incorrect
The ActionChains class is used to perform complex user interactions like drag and drop.
2fill in blank
mediumComplete the code to locate the draggable element by its ID.
Selenium Python
draggable = driver.find_element([1], "draggable")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.CLASS_NAME or By.NAME instead of By.ID.
✗ Incorrect
To find an element by its ID, use By.ID.
3fill in blank
hardFix the error in the drag and drop action method call.
Selenium Python
actions = ActionChains(driver)
actions.[1](draggable, droppable).perform() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names like dragdrop or dragdrop_action.
✗ Incorrect
The correct method to perform drag and drop is drag_and_drop.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps element text to its attribute.
Selenium Python
result = {elem.text: elem.get_attribute([1]) for elem in elements if elem.text [2] ''} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of != in the condition.
Using wrong attribute names.
✗ Incorrect
The attribute to get is "id", and the condition checks that text is not empty using !=.
5fill in blank
hardFill all three blanks to create a filtered dictionary from elements with text length greater than 3.
Selenium Python
filtered = {elem.[1]: elem.get_attribute([2]) for elem in elements if len(elem.[3]) > 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using tag_name instead of text.
Using wrong attribute names.
✗ Incorrect
Use text to get visible text, "data-value" as attribute, and check length of text.