There are many solutions for interaction with alerts
in web pages using Selenium
in Python
. But, I want a solution to find that the page has an alert
or no. Use of Try & except
is very bad solution in my case. So, don't present that. I want just a simple if & else
solution.
This is my solution:
if driver.switch_to_alert()
alert = driver.switch_to_alert()
alert.accept()
else:
print('hello')
NoAlertPresentException: no such alert
(Session info: chrome=73.0.3683.103)
(Driver info: chromedriver=2.46.628402 (536cd7adbad73a3783fdc2cab92ab2ba7ec361e1),platform=Windows NT 10.0.16299 x86_64)