|
1 | 1 | ---
|
2 |
| -title: "JavaScript alerts, prompts and confirmations" |
| 2 | +title: "JavaScript 警告框,提示框和确认框" |
3 | 3 | weight: 6
|
4 | 4 | ---
|
5 | 5 |
|
6 |
| -{{% notice info %}} |
7 |
| -<i class="fas fa-language"></i> 页面需要从英语翻译为简体中文。 |
8 |
| -您熟悉英语与简体中文吗?帮助我们翻译它,通过 pull requests 给我们! |
9 |
| -{{% /notice %}} |
| 6 | +WebDriver提供了一个API, 用于处理JavaScript提供的三种类型的原生弹窗消息. 这些弹窗由浏览器提供限定的样式. |
10 | 7 |
|
11 |
| -WebDriver provides an API for working with the three types of native |
12 |
| -popup message offered by JavaScript. These popups are styled by the |
13 |
| -browser and offer limited customisation. |
| 8 | +## Alerts 警告框 |
14 | 9 |
|
15 |
| -## Alerts |
| 10 | +其中最基本的称为警告框, 它显示一条自定义消息, 以及一个用于关闭该警告的按钮, 在大多数浏览器中标记为"确定"(OK). 在大多数浏览器中, 也可以通过按"关闭"(close)按钮将其关闭, 但这始终与“确定”按钮具有相同的作用. <a onclick="window.alert('Sample alert')">查看样例警告框</a>. |
16 | 11 |
|
17 |
| -The simplest of these is referred to as an alert, which shows a |
18 |
| -custom message, and a single button which dismisses the alert, labelled |
19 |
| -in most browsers as OK. It can also be dismissed in most browsers by |
20 |
| -pressing the close button, but this will always do the same thing as |
21 |
| -the OK button. <a onclick="window.alert('Sample alert')">See an example alert</a>. |
22 |
| - |
23 |
| -WebDriver can get the text from the popup and accept or dismiss these |
24 |
| -alerts. |
| 12 | +WebDriver可以从弹窗获取文本并接受或关闭这些警告. |
25 | 13 |
|
26 | 14 | {{< code-tab >}}
|
27 | 15 | {{< code-panel language="java" >}}
|
@@ -109,13 +97,11 @@ alert.accept()
|
109 | 97 | {{< / code-panel >}}
|
110 | 98 | {{< / code-tab >}}
|
111 | 99 |
|
112 |
| -## Confirm |
| 100 | +## Confirm 确认框 |
113 | 101 |
|
114 |
| -A confirm box is similar to an alert, except the user can also choose |
115 |
| -to cancel the message. <a onclick="window.confirm('Are you sure?')">See |
116 |
| -a sample confirm</a>. |
| 102 | +确认框类似于警告框, 不同之处在于用户还可以选择取消消息. <a onclick="window.confirm('Are you sure?')">查看样例确认框</a>. |
117 | 103 |
|
118 |
| -This example also shows a different approach to storing an alert: |
| 104 | +此示例还呈现了警告的另一种实现: |
119 | 105 |
|
120 | 106 | {{< code-tab >}}
|
121 | 107 | {{< code-panel language="java" >}}
|
@@ -215,14 +201,11 @@ alert.dismiss()
|
215 | 201 | {{< / code-panel >}}
|
216 | 202 | {{< / code-tab >}}
|
217 | 203 |
|
218 |
| -## Prompt |
| 204 | +## Prompt 提示框 |
219 | 205 |
|
220 |
| -Prompts are similar to confirm boxes, except they also include a text |
221 |
| -input. Similar to working with form elements, you can use WebDriver's |
222 |
| -send keys to fill in a response. This will completely replace the placeholder |
223 |
| -text. Pressing the cancel button will not submit any text. |
| 206 | +提示框与确认框相似, 不同之处在于它们还包括文本输入. 与处理表单元素类似, 您可以使用WebDriver的sendKeys来填写响应. 这将完全替换占位符文本. 按下取消按钮将不会提交任何文本. |
224 | 207 | <a onclick="window.prompt('What is your tool of choice?',navigator.appName)">
|
225 |
| -See a sample prompt</a>. |
| 208 | +查看样例提示框</a>. |
226 | 209 |
|
227 | 210 |
|
228 | 211 | {{< code-tab >}}
|
|
0 commit comments