0
0
Selenium Pythontesting~10 mins

Element-level screenshot 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 take a screenshot of a web element using Selenium in Python.

Selenium Python
element = driver.find_element(By.ID, 'logo')
element.[1]('logo.png')
Drag options to blanks, or click blank then click option'
Ascreenshot
Bsave_screenshot
Ccapture
Dtake_screenshot
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.save_screenshot instead of element.screenshot
Using incorrect method names like capture or take_screenshot
2fill in blank
medium

Complete the code to import the correct Selenium module for locating elements.

Selenium Python
from selenium.webdriver.common.by import [1]
Drag options to blanks, or click blank then click option'
ABy
BLocator
CFindBy
DElementBy
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like Locator or FindBy
Trying to import element locating functions instead of the By class
3fill in blank
hard

Fix the error in the code to correctly save an element screenshot.

Selenium Python
element = driver.find_element(By.CLASS_NAME, 'header')
element.[1]('header.png')
Drag options to blanks, or click blank then click option'
Acapture_screenshot
Btake_screenshot
Cscreenshot
Dsave_screenshot
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.save_screenshot instead of element.screenshot
Using method names that do not exist on the element object
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps element IDs to their screenshots saved as PNG files.

Selenium Python
elements = driver.find_elements(By.TAG_NAME, 'img')
screenshots = {el.get_attribute([1]): el.[2](f"{el.get_attribute([1])}.png") for el in elements}
Drag options to blanks, or click blank then click option'
A'id'
Bscreenshot
C'src'
Dsave_screenshot
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'src' instead of 'id' for keys
Using driver methods instead of element methods for screenshots
5fill in blank
hard

Fill all three blanks to write a test that asserts an element screenshot file exists after saving.

Selenium Python
import os

logo = driver.find_element(By.ID, [1])
logo.[2]('logo.png')
assert os.path.[3]('logo.png')
Drag options to blanks, or click blank then click option'
A'logo'
Bscreenshot
Cexists
Dsave_screenshot
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect method names for saving screenshots
Checking file existence with wrong os.path functions