Complete the code to open a browser using Selenium WebDriver.
from selenium import webdriver driver = webdriver.[1]() driver.get('https://example.com') driver.quit()
The webdriver.Chrome() command opens a Chrome browser instance. Selenium supports multiple browsers, but Chrome is commonly used.
Complete the code to find an element by its ID.
from selenium.webdriver.common.by import By element = driver.find_element(By.[1], 'submit-button')
To find an element by its ID attribute, use By.ID. This is the most direct way to locate elements with unique IDs.
Fix the error in the code to click a button after waiting for it to be clickable.
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()
The element_to_be_clickable condition waits until the element is visible and enabled so it can be clicked safely.
Fill both blanks to create a dictionary comprehension that maps element texts to their IDs for all buttons.
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] ''}
The code gets the 'id' attribute of each button and includes only buttons with non-empty text (using '!=' '').
Fill all three blanks to create a dictionary comprehension that maps uppercase button texts to their IDs if the ID starts with 'btn'.
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')}
The code converts button text to uppercase, gets the 'id' attribute, and filters buttons whose ID starts with 'btn'.