An element-level screenshot captures only a specific web element on the page, not the entire browser window. It helps focus on the part of the page you want to test or verify.
Click to reveal answer
beginner
How do you take an element-level screenshot using Selenium in Python?
You first locate the element using a locator (like find_element), then call the method element.screenshot('filename.png') to save the screenshot of that element only.
Click to reveal answer
intermediate
Why is it better to use element-level screenshots instead of full-page screenshots for some tests?
Element-level screenshots are smaller, faster to capture, and focus on the exact part of the page you want to check. This reduces noise and makes debugging easier.
Click to reveal answer
intermediate
What is a good practice when choosing locators for element-level screenshots?
Use stable and unique locators like IDs or data-test attributes. Avoid fragile locators like absolute XPaths that can break easily when the page changes.
Click to reveal answer
beginner
Show a simple Python Selenium code snippet to take an element-level screenshot of a button with id 'submit-btn'.
Hint: Call screenshot() on element, not driver [OK]
Common Mistakes:
Calling screenshot on driver instead of element
Using non-existent methods like save_screenshot on element
Passing element as argument to driver methods
3. Given the code snippet:
element = driver.find_element(By.ID, 'logo')
element.screenshot('logo.png')
What will happen if the element with ID 'logo' is not visible on the page?
medium
A. The screenshot will be taken but the image will be blank or empty.
B. An exception will be raised because the element is not visible.
C. The entire page screenshot will be saved instead.
D. The file 'logo.png' will not be created.
Solution
Step 1: Understand element visibility effect on screenshot
If the element is found but not visible, Selenium still takes a screenshot of the element's area, which may be blank.
Step 2: Confirm behavior on invisible elements
No exception is raised for invisibility; the file is created but image content is empty or transparent.
Final Answer:
The screenshot will be taken but the image will be blank or empty. -> Option A
Quick Check:
Invisible element screenshot = blank image [OK]
Hint: Invisible element screenshot saves blank image, no error [OK]
Common Mistakes:
Expecting an exception for invisible elements
Thinking full page screenshot is saved
Assuming file won't be created
4. Identify the error in this code snippet:
element = driver.find_element(By.CLASS_NAME, 'submit-btn')
element.screenshot = 'submit.png'
medium
A. The element variable should be a list, not a single element.
B. The locator By.CLASS_NAME is invalid.
C. Incorrect assignment; screenshot is a method, not a property.
D. The filename must be a full path, not just 'submit.png'.
Solution
Step 1: Check method usage for screenshot
The code assigns a string to element.screenshot, but screenshot is a method and must be called with parentheses.
Step 2: Confirm correct method call syntax
The correct usage is element.screenshot('submit.png'), not assignment.
Final Answer:
Incorrect assignment; screenshot is a method, not a property. -> Option C
Quick Check:
Use parentheses to call screenshot() method [OK]
Hint: Remember: screenshot is a method, call with () [OK]
Common Mistakes:
Assigning filename to screenshot instead of calling method
Using wrong locator strategy
Expecting list when find_element returns single element
5. You want to take screenshots of multiple buttons on a page and save them as 'button1.png', 'button2.png', etc. Which code snippet correctly does this?
hard
A. buttons = driver.find_elements(By.TAG_NAME, 'button')
for i, btn in enumerate(buttons, 1):
btn.screenshot(f'button{i}.png')
B. buttons = driver.find_elements(By.TAG_NAME, 'button')
for i in range(len(buttons)):
buttons.screenshot(f'button{i}.png')
C. buttons = driver.find_element(By.TAG_NAME, 'button')
for i, btn in enumerate(buttons):
btn.screenshot('button.png')
D. buttons = driver.find_elements(By.CLASS_NAME, 'button')
for btn in buttons:
btn.screenshot('button.png')
Solution
Step 1: Locate multiple elements correctly
Use find_elements to get a list of all buttons by tag name 'button'.
Step 2: Loop with index and save unique filenames
Use enumerate starting at 1 to create filenames like 'button1.png', 'button2.png'. Call btn.screenshot() on each element.
Final Answer:
buttons = driver.find_elements(By.TAG_NAME, 'button')
for i, btn in enumerate(buttons, 1):
btn.screenshot(f'button{i}.png') -> Option A
Quick Check:
Loop elements with enumerate and call screenshot() [OK]
Hint: Use enumerate to name files uniquely in loop [OK]
Common Mistakes:
Calling screenshot on list instead of element
Using find_element instead of find_elements for multiple
Saving all screenshots with same filename
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.