Complete the code to find a button by its ID using Selenium.
button = driver.find_element_by_[1]('submit-btn')
The id locator is used to find an element with a specific ID attribute, which is unique on the page.
Complete the code to locate an element using XPath in Selenium.
element = driver.find_element_by_[1]('//div[@class="content"]')
XPath is used to locate elements by their path in the HTML structure, useful when IDs or classes are not available.
Fix the error in the code to correctly locate an element by CSS selector.
element = driver.find_element_by_[1]('.main-content > p')
The css_selector locator is used to find elements matching CSS selectors, like '.main-content > p'.
Fill both blanks to create a dictionary comprehension that maps element texts to their IDs for elements with class 'item'.
elements = driver.find_elements_by_class_name('item') text_id_map = [1]: el.get_attribute('id') for el in elements if el.text [2] ''
The dictionary comprehension uses {el.text: el.get_attribute('id')} to map text to ID, and filters out empty texts with != ''.
Fill all three blanks to create a test assertion that checks if the page title contains the word 'Dashboard'.
title = driver.title assert [1] in [2], 'Title does not contain [3]'
The assertion checks if the string 'Dashboard' is in the variable title. The message shows if the check fails.