Bird
Raised Fist0
Selenium Pythontesting~20 mins

Window size control in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Window Size Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What 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()
A{'width': 800, 'height': 600}
B{'width': 1024, 'height': 768}
C{'width': 0, 'height': 0}
DRaises an exception
Attempts:
2 left
💡 Hint
The set_window_size method sets the browser window to the specified width and height.
❓ assertion
intermediate
2:00remaining
Which 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()
Aassert size.width == 1024
Bassert size['width'] == 1024
Cassert size.get('height') == 1024
Dassert size['width'] > 1024
Attempts:
2 left
💡 Hint
get_window_size returns a dictionary with keys 'width' and 'height'.
🔧 Debug
advanced
2:00remaining
Why 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()
Awebdriver.Chrome() must be called with options argument
Bdriver.get_window_size() is deprecated and causes error
Cset_window_size requires two arguments: width and height
Dset_window_size only accepts string arguments
Attempts:
2 left
💡 Hint
Check the method signature for set_window_size.
🧠 Conceptual
advanced
2:00remaining
What 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?
AThe window size will be 800x600 as set by set_window_size
BThe window size will be the default browser size
CThe window remains maximized ignoring set_window_size
DAn error is raised because maximize_window conflicts with set_window_size
Attempts:
2 left
💡 Hint
Later commands override earlier ones.
❓ framework
expert
3:00remaining
How 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?
AUse driver.get_window_size() only without resizing
BUse driver.maximize_window() and assume layout adapts automatically
CManually resize the browser window during test execution
DUse driver.set_window_size() to resize, then assert layout changes using element properties
Attempts:
2 left
💡 Hint
Automate resizing and verify layout programmatically.

Practice

(1/5)
1. What does the Selenium method set_window_size(width, height) do in a test script?
easy
A. It refreshes the current browser window.
B. It maximizes the browser window to full screen.
C. It changes the browser window size to the specified width and height.
D. It closes the browser window.

Solution

  1. Step 1: Understand the method purpose

    The method set_window_size(width, height) is designed to set the browser window to a specific size.
  2. Step 2: Compare with other window methods

    Maximizing, closing, or refreshing are done by different methods like maximize_window(), close(), or refresh().
  3. Final Answer:

    It changes the browser window size to the specified width and height. -> Option C
  4. Quick Check:

    set_window_size changes size [OK]
Hint: Remember: set_window_size sets exact width and height [OK]
Common Mistakes:
  • Confusing set_window_size with maximize_window
  • Thinking it closes or refreshes the window
  • Using wrong method names
2. Which of the following is the correct syntax to set the browser window size to 1024x768 in Selenium Python?
easy
A. driver.set_window_size(1024, 768)
B. driver.setWindowSize(1024, 768)
C. driver.window_size(1024, 768)
D. driver.set_size(1024, 768)

Solution

  1. Step 1: Identify correct method name and syntax

    The correct method in Selenium Python is set_window_size(width, height) with underscore and lowercase.
  2. Step 2: Check method call format

    It is called on the driver object as driver.set_window_size(1024, 768).
  3. Final Answer:

    driver.set_window_size(1024, 768) -> Option A
  4. Quick Check:

    Correct method name and parameters [OK]
Hint: Use underscores and lowercase for Selenium Python methods [OK]
Common Mistakes:
  • Using camelCase instead of snake_case
  • Calling non-existent methods like set_size
  • Missing driver object before method
3. What will be the output of the following code snippet?
driver.set_window_size(800, 600)
size = driver.get_window_size()
print(size)
medium
A. {'width': 800, 'height': 600}
B. {'width': 600, 'height': 800}
C. An error because get_window_size() does not exist
D. None

Solution

  1. Step 1: Understand set_window_size effect

    The window size is set to width=800 and height=600.
  2. Step 2: Check get_window_size output

    The method get_window_size() returns a dictionary with keys 'width' and 'height' reflecting the current window size.
  3. Final Answer:

    {'width': 800, 'height': 600} -> Option A
  4. Quick Check:

    get_window_size returns current size dict [OK]
Hint: get_window_size returns dict with width and height keys [OK]
Common Mistakes:
  • Swapping width and height values
  • Assuming get_window_size() does not exist
  • Expecting a tuple instead of dict
4. Identify the error in this Selenium Python code snippet that tries to set the window size:
driver.set_window_size(1024)
medium
A. Method name should be setWindowSize, not set_window_size.
B. Missing the height parameter in set_window_size method.
C. The driver object is not defined.
D. set_window_size cannot be called directly on driver.

Solution

  1. Step 1: Check method parameters

    The method set_window_size requires two parameters: width and height.
  2. Step 2: Identify missing argument

    Only one argument (1024) is provided, so height is missing, causing a TypeError.
  3. Final Answer:

    Missing the height parameter in set_window_size method. -> Option B
  4. Quick Check:

    Two parameters required for set_window_size [OK]
Hint: Always provide both width and height to set_window_size [OK]
Common Mistakes:
  • Providing only one parameter instead of two
  • Using camelCase method name in Python
  • Assuming driver is undefined without context
5. You want to test a website's responsive design by setting the browser window to three sizes: 320x480, 768x1024, and 1920x1080. Which code snippet correctly sets these sizes one after another with Selenium Python?
hard
A. sizes = [(320, 480), (768, 1024), (1920, 1080)] for size in sizes: driver.set_window_size(size)
B. sizes = [320, 480, 768, 1024, 1920, 1080] for size in sizes: driver.set_window_size(size)
C. driver.setWindowSize(320, 480) driver.setWindowSize(768, 1024) driver.setWindowSize(1920, 1080)
D. sizes = [(320, 480), (768, 1024), (1920, 1080)] for w, h in sizes: driver.set_window_size(w, h)

Solution

  1. Step 1: Understand the sizes list format

    Sizes should be stored as tuples of (width, height) for easy unpacking.
  2. Step 2: Use a for loop with unpacking

    Loop over sizes and unpack each tuple into width and height to call set_window_size(w, h).
  3. Step 3: Eliminate incorrect options

    sizes = [320, 480, 768, 1024, 1920, 1080] for size in sizes: driver.set_window_size(size) uses a flat list and passes single integers (missing height parameter). driver.setWindowSize(320, 480) driver.setWindowSize(768, 1024) driver.setWindowSize(1920, 1080) uses camelCase setWindowSize (incorrect for Python Selenium). sizes = [(320, 480), (768, 1024), (1920, 1080)] for size in sizes: driver.set_window_size(size) loops but passes tuples directly (TypeError, expects two arguments).
  4. Final Answer:

    sizes = [(320, 480), (768, 1024), (1920, 1080)] for w, h in sizes: driver.set_window_size(w, h) -> Option D
  5. Quick Check:

    Use tuple unpacking for width and height [OK]
Hint: Use tuple unpacking in loop to set window sizes [OK]
Common Mistakes:
  • Passing single integers instead of width and height pairs
  • Calling set_window_size with a tuple instead of two arguments
  • Using camelCase (setWindowSize) instead of snake_case
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard