Challenge - 5 Problems
Key Combination Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Python code snippet?
Consider the following Selenium Python code that sends a key combination to an input field. What will be the final text entered in the input field?
Selenium Python
from selenium.webdriver import Chrome from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains browser = Chrome() browser.get('https://example.com') input_field = browser.find_element(By.ID, 'search') actions = ActionChains(browser) actions.key_down(Keys.SHIFT, input_field).send_keys('hello').key_up(Keys.SHIFT, input_field).perform()
Attempts:
2 left
💡 Hint
Think about what holding down SHIFT does to lowercase letters.
✗ Incorrect
Holding down the SHIFT key while sending 'hello' causes the letters to be typed in uppercase, resulting in 'HELLO'.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies that CTRL+A was sent to select all text?
You want to verify that sending CTRL+A to an input field selects all text. Which assertion correctly checks this behavior after sending the keys?
Selenium Python
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains input_field = driver.find_element(By.ID, 'text') actions = ActionChains(driver) actions.click(input_field).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).perform() # Which assertion below correctly verifies the selection?
Attempts:
2 left
💡 Hint
Selection is a browser property, not an input attribute.
✗ Incorrect
The JavaScript window.getSelection() returns the selected text in the page. Comparing it to the input's value confirms all text is selected.
❓ locator
advanced2:00remaining
Identify the best locator for an input field to send key combinations
You need to send key combinations to an input field that has dynamic IDs but a stable placeholder attribute 'Enter your name'. Which locator is best for this purpose?
Attempts:
2 left
💡 Hint
Dynamic IDs change, so avoid them. Use stable attributes.
✗ Incorrect
Using the placeholder attribute with a CSS selector is stable and reliable when IDs are dynamic.
🔧 Debug
advanced2:00remaining
Why does this Selenium key combination code raise an error?
Examine the code below. It raises an error when run. What is the cause?
Selenium Python
actions = ActionChains(driver)
actions.key_down(Keys.CONTROL).send_keys('c').perform()
actions.key_up(Keys.CONTROL).perform()Attempts:
2 left
💡 Hint
ActionChains perform() executes the chain and resets it.
✗ Incorrect
Calling perform() ends the current chain. key_up must be in the same chain as key_down to release the key properly.
❓ framework
expert3:00remaining
How to implement a reusable method to send SHIFT+text using Selenium Python?
You want to create a reusable Python method using Selenium that sends SHIFT+text (uppercase) to any input element. Which implementation is correct and follows best practices?
Attempts:
2 left
💡 Hint
Always click the element before sending keys to ensure focus.
✗ Incorrect
Option D clicks the element to focus, then holds SHIFT while sending text, then releases SHIFT, all in one chain. This is the correct and reliable approach.