How can I handle a Confirmation Alert pop-up using Python Webdriver?

How can I handle a Confirmation Alert pop-up using Python Webdriver?

Hello Toby-steed,

To handle a confirmation alert pop-up using Python WebDriver, you can use the switch_to.alert method along with the accept() or dismiss() methods. Here’s an example:

driver = webdriver.Firefox()
driver.maximize_window()
driver.get(url)

#Switch the control to the Alert window
obj = driver.switch_to.alert

#Retrieve the message on the Alert window
message=obj.text
print ("Alert shows following message: "+ message )

time.sleep(2)

#use the accept() method to accept the alert
obj.accept()

# Or Dismiss the Alert using
obj.dismiss()

driver.close