> For the complete documentation index, see [llms.txt](https://tesseractcoder.gitbook.io/simple-selenium-wrapper-python/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tesseractcoder.gitbook.io/simple-selenium-wrapper-python/fundamentals-of-automation/handling-alerts.md).

# Handling Alerts

### Introduction

Sometimes when building automation scripts, you'll need to deal with popup alerts. Handling alerts with Simple Selenium is dead simple, which you'll learn all about on this page.

### Simple Selenium Alerts

Interacting with alerts in Simple Selenium is simple. See the example below, which visits an alert test page & handles the alert:

```python
#Start chrome webdriver with custom options
driver=SimpleSelenium("chrome",save_profile=True,profile_name="myAwesomeProfile",save_logs_in_file=True,maximized=False)

#Visit Alert Test Page
driver.visit("https://testpages.herokuapp.com/styled/alerts/alert-test.html")

#Waits 2 seconds
time.sleep(2)

#Clicks "Show Prompt Box" btn
driver.by_id('promptexample').click()

#Waits 1 second
time.sleep(1)

#You can access the Alerts class with driver.alerts

#Writes text to alert box
driver.alerts.write("Some text to type")

#Accepts alert box
driver.alerts.accept()

```

### List of All Alert Functions

Below, are a list of all alert-based functions that Simple Selenium offers.

#### Accept Alert Box

To accept an alert box:

```python
driver.alerts.accept() #Accepts alert box

#Default options:
retry_if_fail=True #Whether or not to retry if handling alert fails
max_retries=5 #Max number of retries before returning False (if retry_if_fail==True)
delay_for_each_retry=1 #Time delay between each retry in seconds (if retry_if_fail==True)

driver.alerts.accept(retry_if_fail=False) #Doesn't retry if initial attempt to handle alert fails
```

#### Dismiss Alert Box

To dismiss an alert box:

```python
driver.alerts.dismiss() #Accepts alert box

#Default options:
retry_if_fail=True #Whether or not to retry if handling alert fails
max_retries=5 #Max number of retries before returning False (if retry_if_fail==True)
delay_for_each_retry=1 #Time delay between each retry in seconds (if retry_if_fail==True)

driver.alerts.dismiss(retry_if_fail=False) #Doesn't retry if initial attempt to handle alert fails
```

#### Write To Alert Box

To write text to an alert box:

```python
driver.alerts.write("Text to write") #Writes text to an alert box

#Default options:
retry_if_fail=True #Whether or not to retry if handling alert fails
max_retries=5 #Max number of retries before returning False (if retry_if_fail==True)
delay_for_each_retry=1 #Time delay between each retry in seconds (if retry_if_fail==True)

driver.alerts.write("Text to write",retry_if_fail=False) #Doesn't retry if initial attempt to handle alert fails
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://tesseractcoder.gitbook.io/simple-selenium-wrapper-python/fundamentals-of-automation/handling-alerts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
