Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

I'm trying to write a test with selenium in python language for a web page that manages users. In this page, someone can add a role for users and if a role exists while adding it, an alert raises. I don't know if the alert is a javascript alert or an element of the web page. I want to automatically check the existence of the alert, because checking for the role in the list wastes time and has an enormous load. I tried this:

browser = webdriver.Firefox()




    alert = browser.switch_to_alert()


    print "alert accepted"


    print "no alert"

But it didn't work and I got the "UnexpectedAlertPresentException". I also tried this:

browser = webdriver.Firefox()



s = set(browser.window_handles)



But I got the same exception. Additionally, I tried to access the alert with firebug to check if I can get access with its properties, but right-click was disabled. I need a solution very quickly, even in other languages. I can understand the approach anyway. I will appreciate any help.

1 Answer

0 votes
by (62.9k points)

In java, we do it like this

WebDriverWait wait = new WebDriverWait(driver, 7000);



It will wait for an alert if an alert is not present, implicitly and it will throw 'Alert is not present Exception' which can be caught by us and we can move ahead.

 I hope it helps.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, you should enroll yourself in industry-based Selenium online courses!

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.2k users

Browse Categories