How to handle alert prompts in Selenium Python ? Last Updated : 20 Feb, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Selenium’s Python Module is built to perform automated testing with Python. Alerts are a way to show popups in the browser for either accepting data or displaying data. Selenium provides methods to handle alerts of all kinds. Selenium’s Python Module is built to perform automated testing with Python. Alerts are a way to show popups in the browser for either accepting data or displaying data. Selenium provides methods to handle alerts of all kinds. class selenium.webdriver.common.alert.Alert(driver) handles all alerts in Selenium Python. It contains methods for dismissing, accepting, inputting, and getting text from alert prompts. The two major tasks in alerts are accepting an alert or dismissing a alert.Selenium provides two methods for the same:Alert(driver).accept()Alert(driver).dismiss()Alert MethodsThe major methods during handling of alerts in Selenium include –accept() – Accepts the alert available.dismiss() – Dismisses the alert available.send_keys(keysToSend) – Send Keys to the Alert.text – Gets the text of the Alert.How to operate on an alert prompt using Selenium Python ?To illustrate alerts, let’s write manual javascript alert and check various methods on the same. We have created an example link – https://ide.geeksforgeeks.org/tryit.php/WXYeMD9tD4 Python from selenium import webdriver from selenium.webdriver.common.alert import Alert import time # Create WebDriver object driver = webdriver.Firefox(executable_path="path_to_geckodriver") # Make sure to specify the correct path to geckodriver # Navigate to the webpage (Ensure the URL is correct without spaces) driver.get("https://ide.geeksforgeeks.org/tryit.php/WXYeMD9tD4") # Wait for the alert to appear (you might need to adjust the time based on your page load time) time.sleep(3) # Switch to the alert alert = Alert(driver) # Get the alert text print(alert.text) # Accept the alert alert.accept() # Close the browser driver.quit() Output - Terminal Output - Comment More infoAdvertise with us Next Article parent element method - Selenium Python N NaveenArora Follow Improve Article Tags : Python Python-selenium Practice Tags : python Similar Reads Python - find_element() method in Selenium While performing any action on a web page using selenium, there is need of locators to perform specific tasks. Locators in web page are used to identify unique elements within a webpage. Web elements could be anything that the user sees on the page, such as title, table, links, buttons, toggle butto 2 min read Element methods in Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. Selenium in Python works with elements. An element can be a tag, property, or anything, it is an instance of class selenium.webdriver.remote.webelement.WebElement. After you find an element on screen using selenium, you migh 3 min read parent element method - Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout - Navigating links using get method â Selenium Python. Just bein 2 min read location element method - Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout - Navigating links using get method â Selenium Python. Just bein 2 min read is_enabled() element method - Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout - Navigating links using get method â Selenium Python. Just bein 2 min read Web Driver Methods in Selenium Python Seleniumâs Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout â Navigating links using get method â Selenium Python. Just bein 5 min read Like