How a prompt alert can be handled in Python Selenium Webdriver

0 votes
How a prompt alert can be handled in Python Selenium Webdriver?
Jul 29, 2019 in Selenium by Duran
1,291 views

1 answer to this question.

0 votes

Hey Duran, you can handle a prompt alert using following automation script:

from selenium import webdriver
import time

driver = webdriver.Firefox()
driver.maximize_window()
location = "https://www.edureka.co/"
driver.get(location)

button = driver.find_element_by_name('continue')
button.click()

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

time.sleep(2)

#Enter text into the Alert using send_keys()
obj.send_keys('Ramesh')

time.sleep(2)

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

message=obj.text
print ("Alert shows following message: "+ message )

time.sleep(2)

obj.accept()

#get the text returned when OK Button is clicked.
txt = driver.find_element_by_id('msg')
print(txt.text)

driver.close
answered Jul 30, 2019 by Abha
• 28,140 points

Related Questions In Selenium

0 votes
1 answer

Can anyone explain how an AJAX call can be handled in Selenium webdriver?

Hello Megha, to demonstrate how AJAX calls are ...READ MORE

answered May 9, 2019 in Selenium by Pratibha
• 3,690 points
1,187 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How can I create a POM test case in Selenium Webdriver?

Hey Akshay, follow these steps to create ...READ MORE

answered May 13, 2019 in Selenium by Anvi
• 14,150 points
1,220 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,187 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
12,717 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
8,611 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
6,685 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
8,899 views
0 votes
1 answer
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