Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to switch to the confirmation alert.
Selenium Python
alert = driver.switch_to.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the parentheses after alert
Using incorrect method names like confirm or alert_switch
✗ Incorrect
The switch_to.alert() method switches the driver focus to the alert popup.
2fill in blank
mediumComplete the code to accept the confirmation alert.
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() which cancels the alert
Trying to use close() which is not valid for alerts
✗ Incorrect
The accept() method clicks the OK button on the confirmation alert.
3fill in blank
hardFix the error in the code to dismiss the confirmation alert.
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 accept() instead of dismiss()
Using close() or cancel() which are not valid alert methods
✗ Incorrect
The dismiss() method clicks the Cancel button on the confirmation alert.
4fill in blank
hardFill both blanks to get the alert text and then accept the alert.
Selenium Python
alert = driver.switch_to.[1]() text = alert.[2] alert.accept()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dismiss() instead of alert() to switch
Trying to call text() as a method instead of property
✗ Incorrect
First, switch to the alert using alert(). Then get the alert message text using text.
5fill in blank
hardFill all three blanks to switch to alert, print its text, and dismiss it.
Selenium Python
alert = driver.switch_to.[1]() print(alert.[2]) alert.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling text as a method with parentheses
Using accept() instead of dismiss() to cancel
✗ Incorrect
Switch to the alert with alert(), print the alert message with text, and cancel the alert with dismiss().