How a prompt alert can be handled in Python Selenium WebDriver?

How a prompt alert can be handled in Python Selenium WebDriver?

Hi Brett,

you can handle a prompt alert using the 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