Complete the code to open a Chrome browser using Selenium.
from selenium import webdriver driver = webdriver.[1]() driver.get('https://example.com') driver.quit()
The correct way to open a Chrome browser is to use webdriver.Chrome().
Complete the code to find an element by its ID.
from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get('https://example.com') element = driver.find_element(By.[1], 'submit-button') driver.quit()
By.NAME when the element has an ID.By.ID.To find an element by its ID, use By.ID.
Fix the error in the code to click a button after finding it.
from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get('https://example.com') button = driver.find_element(By.ID, 'submit') button.[1]() driver.quit()
submit() on a button element that is not a form.send_keys() which is for typing text.To click a button, use the click() method.
Fill both blanks to wait until an element is visible before clicking it.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC driver = webdriver.Chrome() driver.get('https://example.com') wait = WebDriverWait(driver, [1]) element = wait.until(EC.[2]((By.ID, 'submit'))) element.click() driver.quit()
visibility_of_element_located when the element is not clickable yet.Use WebDriverWait(driver, 5) to wait 5 seconds, and EC.element_to_be_clickable to wait until the element can be clicked.
Fill all three blanks to create a dictionary of element texts for all buttons with class 'btn'.
from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get('https://example.com') buttons = driver.find_elements(By.[1], 'btn') texts = [2]: button.[3] for button in buttons print(texts) driver.quit()
find_element instead of find_elements.text() as a method instead of property.Find elements by class name using By.CLASS_NAME. Create a dictionary {button.text: button.text for button in buttons} using the button.text property (not button.text()).