0
0
Selenium Pythontesting~10 mins

Why Selenium is the standard for web automation in Selenium Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to open a browser using Selenium WebDriver.

Selenium Python
from selenium import webdriver

driver = webdriver.[1]()
driver.get('https://example.com')
driver.quit()
Drag options to blanks, or click blank then click option'
ASafari
BChrome
CFirefox
DEdge
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase browser names like 'chrome' instead of 'Chrome'.
Forgetting to call the browser constructor as a function.
2fill in blank
medium

Complete the code to find an element by its ID.

Selenium Python
from selenium.webdriver.common.by import By

element = driver.find_element(By.[1], 'submit-button')
Drag options to blanks, or click blank then click option'
ATAG_NAME
BNAME
CCLASS_NAME
DID
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NAME' when the element's ID is needed.
Using string literals instead of By constants.
3fill in blank
hard

Fix the error in the code to click a button after waiting for it to be clickable.

Selenium Python
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

wait = WebDriverWait(driver, 10)
button = wait.until(EC.[1]((By.ID, 'submit-button')))
button.click()
Drag options to blanks, or click blank then click option'
Aelement_to_be_clickable
Bpresence_of_element_located
Cvisibility_of_element_located
Dalert_is_present
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence_of_element_located which does not guarantee clickability.
Using alert_is_present which waits for alerts, not elements.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps element texts to their IDs for all buttons.

Selenium Python
buttons = driver.find_elements(By.TAG_NAME, 'button')
text_id_map = {btn.text: btn.get_attribute([1]) for btn in buttons if btn.text [2] ''}
Drag options to blanks, or click blank then click option'
A'id'
B!=
C==
D'class'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'id' for the attribute.
Using '==' instead of '!=' which would select empty texts.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase button texts to their IDs if the ID starts with 'btn'.

Selenium Python
buttons = driver.find_elements(By.TAG_NAME, 'button')
result = {btn.text.[1](): btn.get_attribute([2]) for btn in buttons if btn.get_attribute([3]).startswith('btn')}
Drag options to blanks, or click blank then click option'
Aupper
B'id'
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lower' instead of 'upper' for text conversion.
Using different attributes for get_attribute calls.