---
title: "selenium 点击alert"
author: "mailx8"
date: "2017-11-28T14:03:39Z"
tags: []
categories: ["Web前端"]
slug: "selenium-alert"
draft: false
lastmod: "2017-11-28T14:03:39Z"
id: 2401113
url: "https://mailx8.iteye.com/blog/2401113"
---

OK， Show you the code：

```
1 driver.findElement(By.id("updateButton")).click();
2 //pop up with id "updateButton" opens
3 Alert alert = driver.switchTo().alert();
4 //update is executed
5 alert.accept();
```

如果是点取消，则：

alert.dismiss();