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
128 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 29, 2019 by Abha
• 27,800 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 8, 2019 in Selenium by Pratibha
• 3,690 points
222 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 12, 2019 in Selenium by Anvi
• 14,010 points
208 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,010 points
653 views
0 votes
1 answer

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,510 points
2,186 views
0 votes
1 answer
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,870 points
1,811 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 2, 2019 in Selenium by Abha
• 27,800 points
744 views
0 votes
1 answer