# Alert Handling in Web Testing

**URL:** <https://forum.katalon.com/t/alert-handling-in-web-testing/61623>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [January 14, 2022, 5:24pm UTC](https://forum.katalon.com/t/alert-handling-in-web-testing/61623 "2022-01-14T17:24:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![subhendu.ghosh](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/subhendu.ghosh/32/16104_2.png) [@subhendu.ghosh](https://forum.katalon.com/u/subhendu.ghosh)\
**Post date:** [January 14, 2022, 5:24pm UTC](https://forum.katalon.com/t/alert-handling-in-web-testing/61623/1 "2022-01-14T17:24:30Z")

</div>

How to handle an alert when it is in a new window and if the window is not loaded fully. This window never loads successfully until unless accept/decline the alert.

 ![image](https://europe1.discourse-cdn.com/katalon/original/3X/5/e/5e38a082a9b2afcc9001e6866e8f6b3bd19e026c.png)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [January 14, 2022, 6:20pm UTC](https://forum.katalon.com/t/alert-handling-in-web-testing/61623/2 "2022-01-14T18:20:49Z")

</div>

What have you tried? What happened?

I’m not sure this will work… try calling switchToWindow\* then immediately handle the alert

```nohighlight
switchToWindowIndex
switchToWindowTitle
switchToWindowUrl

```

---

<div class="post-metadata">

**Author:** ![subhendu.ghosh](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/subhendu.ghosh/32/16104_2.png) [@subhendu.ghosh](https://forum.katalon.com/u/subhendu.ghosh)\
**Post date:** [January 24, 2022, 2:05pm UTC](https://forum.katalon.com/t/alert-handling-in-web-testing/61623/3 "2022-01-24T14:05:33Z")

</div>

I tried all of these “switchToWindow”. In the console window, I can see it is working still “switchToWindow” but after that not able to accept the alert.

---

<div class="post-metadata">

**Author:** ![grylion54](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/grylion54/32/16265_2.png) [@grylion54](https://forum.katalon.com/u/grylion54)\
**Post date:** [January 24, 2022, 3:53pm UTC](https://forum.katalon.com/t/alert-handling-in-web-testing/61623/4 "2022-01-24T15:53:03Z")

</div>

Can you **click** on the OK button in the console window instead?

---

<div class="post-metadata">

**Author:** ![subhendu.ghosh](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/subhendu.ghosh/32/16104_2.png) [@subhendu.ghosh](https://forum.katalon.com/u/subhendu.ghosh)\
**Post date:** [January 25, 2022, 4:04pm UTC](https://forum.katalon.com/t/alert-handling-in-web-testing/61623/5 "2022-01-25T16:04:21Z")

</div>

No. After “switchToWindow” the click also not working.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [January 25, 2022, 5:23pm UTC](https://forum.katalon.com/t/alert-handling-in-web-testing/61623/6 "2022-01-25T17:23:00Z")

</div>

A couple ideas:

1.) After switching to the new window, do another switch to the alert modal and accept it:

```
// switch to new window first... then:

WebDriver driver = DriverFactory.getWebDriver();
driver.switchTo().alert().accept();

```

2.) Use desired capabilities to ignore all alerts:

Add this as an argument to your desired capabilities:

`--disable-notifications`

Here’s more info on how to add desired capabilities:

> **[Introduction to desired capabilities](https://docs.katalon.com/katalon-studio/docs/introduction-to-desired-capabilities.html)**
>
> Desired capabilities are key/value pairs that tell the browser properties such as browser name, browser version, and the path of the browser driver in the system to determine the browsers'...
