Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to take a screenshot of the element.
Selenium Python
element = driver.find_element(By.ID, "logo") element.[1]("logo.png")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'screenshot'.
Trying to use 'get_attribute' to save an image.
Using 'send_keys' which is for typing text.
✗ Incorrect
The method to take a screenshot of a web element in Selenium Python is 'screenshot'.
2fill in blank
mediumComplete the code to find the element by CSS selector before taking a screenshot.
Selenium Python
element = driver.find_element(By.[1], "#header") element.screenshot("header.png")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.ID when the selector is a CSS selector.
Using By.NAME which looks for the name attribute.
Using By.XPATH which requires XPath syntax.
✗ Incorrect
To find an element by CSS selector, use By.CSS_SELECTOR.
3fill in blank
hardFix the error in the code to correctly save the element screenshot.
Selenium Python
element = driver.find_element(By.CLASS_NAME, "banner") element.[1]("banner_screenshot.png")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'save_screenshot' which is a driver method, not element method.
Using non-existent methods like 'capture' or 'take_screenshot'.
✗ Incorrect
The correct method to save an element screenshot is 'screenshot'. 'save_screenshot' is for the whole page.
4fill in blank
hardFill both blanks to take a screenshot of the element found by XPath.
Selenium Python
element = driver.find_element(By.[1], "//div[@class='content']") element.[2]("content.png")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.ID or By.CLASS_NAME for XPath selectors.
Using 'save_screenshot' instead of 'screenshot' on element.
✗ Incorrect
Use By.XPATH to find the element by XPath and 'screenshot' method to save the element image.
5fill in blank
hardFill all three blanks to find an element by name, take its screenshot, and save with a dynamic filename.
Selenium Python
element = driver.find_element(By.[1], "profilePic") filename = f"[2]_screenshot.png" element.[3](filename)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.ID instead of By.NAME.
Using a string literal instead of variable in filename.
Using 'save_screenshot' instead of 'screenshot' on element.
✗ Incorrect
Find element by name using By.NAME, use the variable 'profilePic' for filename, and call 'screenshot' method.