0
0
Selenium Pythontesting~10 mins

Why alert handling prevents test failures in Selenium Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to switch to the alert box.

Selenium Python
alert = driver.switch_to.[1]()
Drag options to blanks, or click blank then click option'
Aalert
Balert_box
Dalert()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'alert' without parentheses returns the property, not the alert object.
Trying to call a non-existent method like 'alert_box()'.
2fill in blank
medium

Complete the code to accept the alert and prevent test failure.

Selenium Python
alert.[1]()
Drag options to blanks, or click blank then click option'
Aaccept
Bdismiss
Cclose
Dsend_keys
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dismiss()' which cancels the alert instead of accepting it.
Trying to use 'close()' which is not a valid alert method.
3fill in blank
hard

Fix the error in the code to handle alert text correctly.

Selenium Python
alert_text = alert.[1]
Drag options to blanks, or click blank then click option'
Atext
Bget_text()
Ctext()
DgetText()
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text()' or 'get_text()' which cause errors because they are not methods.
Using Java-style 'getText()' which is invalid in Python.
4fill in blank
hard

Fill both blanks to check if alert is present and accept it.

Selenium Python
try:
    alert = driver.switch_to.[1]()
    alert.[2]()
except:
    pass
Drag options to blanks, or click blank then click option'
Aalert
Baccept
Cdismiss
Dalert_box
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dismiss()' instead of 'accept()' which may not be intended.
Trying to use a non-existent 'alert_box()' method.
5fill in blank
hard

Fill all three blanks to get alert text, accept alert, and print the text.

Selenium Python
alert = driver.switch_to.[1]()
alert_text = alert.[2]
alert.[3]()
print(alert_text)
Drag options to blanks, or click blank then click option'
Aalert
Btext
Caccept
Ddismiss
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'dismiss()' instead of 'accept()' which cancels alert.
Trying to call 'text()' as a method instead of property.