Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a browser and navigate to a URL using Selenium.
Selenium Python
driver = webdriver.Chrome() driver.[1]('https://example.com')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'open' or 'navigate' instead of 'get' causes errors.
✗ Incorrect
The get method opens the specified URL in the browser.
2fill in blank
mediumComplete the code to find an element by its ID using Selenium.
Selenium Python
element = driver.find_element(By.[1], 'submit-button')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NAME or CLASS_NAME when the element has an ID.
✗ Incorrect
The ID locator finds an element by its unique ID attribute.
3fill in blank
hardFix the error in the code to wait until an element is clickable before clicking.
Selenium Python
wait = WebDriverWait(driver, 10) element = wait.until(EC.[1]((By.ID, 'submit'))) element.click()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence_of_element_located does not guarantee clickability.
✗ Incorrect
element_to_be_clickable waits until the element can be clicked.
4fill in blank
hardFill both blanks to create a Page Object method that clicks a button after waiting for it.
Selenium Python
def click_submit(self): wait = WebDriverWait(self.driver, 10) button = wait.until(EC.[1]((By.[2], 'submit-btn'))) button.click()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence_of_element_located instead of element_to_be_clickable.
✗ Incorrect
Waiting for the button to be clickable by ID ensures safe clicking.
5fill in blank
hardFill all three blanks to define a test that asserts the page title after navigation.
Selenium Python
def test_page_title(self): self.driver.[1]('https://example.com') title = self.driver.[2] assert title [3] 'Example Domain'
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using current_url instead of title, or wrong comparison operator.
✗ Incorrect
The test opens the page, gets the title, and asserts it equals the expected string.