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 in Selenium by Duran
52 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 by Abha
• 27,200 points

Related Questions In Selenium

0 votes
1 answer
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 in Selenium by Anvi
• 13,960 points
95 views
0 votes
1 answer

Installing Selenium Webdriver with Python package

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

answered May 8 in Selenium by Anvi
• 13,960 points
280 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,430 points
1,190 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,510 points
1,274 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 in Selenium by Abha
• 27,200 points
132 views
0 votes
1 answer