Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to accept a simple alert popup.
Selenium Python
alert = driver.switch_to.alert
alert.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept() will cancel the alert.
Trying to send keys to a simple alert causes an error.
✗ Incorrect
The accept() method clicks the OK button on the alert popup.
2fill in blank
mediumComplete the code to switch to the alert before accepting it.
Selenium Python
driver.[1].alert.accept() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using find_element tries to find a page element, not an alert.
execute_script runs JavaScript but does not switch focus.
✗ Incorrect
The switch_to property allows switching the driver's focus to the alert popup.
3fill in blank
hardFix the error in the code to accept the alert correctly.
Selenium Python
alert = driver.switch_to.[1]
alert.accept() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses after alert causes a TypeError.
Using 'alerts' or 'switch' are invalid attributes.
✗ Incorrect
The alert is a property, not a method, so no parentheses are needed.
4fill in blank
hardFill both blanks to switch to the alert and get its text.
Selenium Python
alert = driver.[1].[2] text = alert.text
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using find_element instead of switch_to.
Using 'alerts' instead of 'alert'.
✗ Incorrect
You switch to the alert using switch_to and access the alert with alert.
5fill in blank
hardFill all three blanks to switch to the alert, get its text, and accept it.
Selenium Python
alert = driver.[1].[2] message = alert.[3] alert.accept()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of accept() to close the alert.
Trying to call text() as a method instead of accessing it as a property.
✗ Incorrect
Switch to the alert, access the alert property, then get its text using text.