Challenge - 5 Problems
Window Size Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the window size after resizing?
Given the following Selenium Python code snippet, what will be the window size after execution?
Selenium Python
from selenium import webdriver options = webdriver.ChromeOptions() driver = webdriver.Chrome(options=options) driver.set_window_size(800, 600) size = driver.get_window_size() print(size) driver.quit()
Attempts:
2 left
💡 Hint
The set_window_size method sets the browser window to the specified width and height.
✗ Incorrect
The code sets the window size to 800 pixels wide and 600 pixels tall, then retrieves the size. So the output is a dictionary with width 800 and height 600.
❓ assertion
intermediateWhich assertion correctly verifies window size?
You want to assert that the browser window width is exactly 1024 pixels after resizing. Which assertion is correct?
Selenium Python
driver.set_window_size(1024, 768) size = driver.get_window_size()
Attempts:
2 left
💡 Hint
get_window_size returns a dictionary with keys 'width' and 'height'.
✗ Incorrect
The size variable is a dictionary, so you must use size['width'] to access the width. Option B correctly asserts width equals 1024.
🔧 Debug
advancedWhy does this window resize code fail?
This Selenium Python code throws an error. What is the cause?
Selenium Python
driver = webdriver.Chrome()
driver.set_window_size(800)
size = driver.get_window_size()Attempts:
2 left
💡 Hint
Check the method signature for set_window_size.
✗ Incorrect
set_window_size requires two integer arguments: width and height. Passing only one argument causes a TypeError.
🧠 Conceptual
advancedWhat happens if you maximize window before setting size?
In Selenium Python, if you call driver.maximize_window() before driver.set_window_size(800, 600), what will be the final window size?
Attempts:
2 left
💡 Hint
Later commands override earlier ones.
✗ Incorrect
Calling set_window_size after maximize_window resizes the window to the specified size, overriding maximization.
❓ framework
expertHow to reliably test window resizing in Selenium tests?
You want to write a Selenium test that verifies your web app layout changes correctly when the window is resized. Which approach is best?
Attempts:
2 left
💡 Hint
Automate resizing and verify layout programmatically.
✗ Incorrect
To test layout changes on resize, you must programmatically resize the window and then check element properties or styles to confirm layout adapts.
