Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a browser using Selenium.
Selenium Python
from selenium import webdriver browser = webdriver.[1]() browser.get('https://example.com')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a browser name not supported or misspelled.
✗ Incorrect
The webdriver.Firefox() command opens a Firefox browser controlled by Selenium.
2fill in blank
mediumComplete the code to find an element by its ID.
Selenium Python
element = browser.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's ID is needed.
✗ Incorrect
To find an element by its ID attribute, use find_element_by_id.
3fill in blank
hardFix the error in the code to click a button.
Selenium Python
button = browser.find_element_by_id('login') button.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'submit' on a button element instead of 'click'.
✗ Incorrect
The click() method simulates a mouse click on the button element.
4fill in blank
hardFill both blanks to wait until an element is visible before clicking.
Selenium Python
from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC wait = WebDriverWait(browser, 10) element = wait.until(EC.[1]((By.[2], 'submit'))) element.click()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using presence_of_element_located which does not guarantee visibility.
✗ Incorrect
Use visibility_of_element_located to wait until the element is visible, and By.ID to locate by ID.
5fill in blank
hardFill all three blanks to write a test that opens a browser, navigates, and asserts the page title.
Selenium Python
from selenium import webdriver browser = webdriver.[1]() browser.get('https://example.com') assert browser.title [2] 'Example Domain' browser.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' in assertion.
Forgetting to close the browser.
✗ Incorrect
The test opens Firefox, checks the page title equals 'Example Domain', then closes the browser with quit().