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

0 votes
May 27, 2019 in Selenium by Sudha
9,451 views

1 answer to this question.

0 votes

Hey Sudha, you can use following code to handle confirmation alert popup using Python webdriver:

from selenium import webdriver
import time

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


I am sure this helped to answer your query, cheers!

For more, join this course to Master Python programming.

Thanks!

answered May 28, 2019 by George

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can I handle Javascript Alert popup using Ruby Selenium webdriver?

Hey Usman, you can use driver.switch_to.alert method ...READ MORE

answered Aug 27, 2019 in Selenium by Abha
• 28,140 points
2,307 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,500 points
10,557 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

Hey Hemant, for installing Selenium Webdriver with ...READ MORE

answered May 8, 2019 in Selenium by Anvi
• 14,150 points
15,838 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,221 views
0 votes
1 answer

How can I send some data to a Prompt Alert box using Selenium Webdriver?

Hey Abhishek, you can use sendKeys() method ...READ MORE

answered Jul 3, 2019 in Selenium by Abha
• 28,140 points
9,538 views
0 votes
1 answer

How can I locate web elements from a web page using Selenium Webdriver?

Hey @Dushyant, Locating elements in WebDriver is ...READ MORE

answered May 29, 2019 in Selenium by Shreya
2,903 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP