@@ -69,7 +69,22 @@ alert.Accept();
69
69
# We don't have a Ruby code sample yet - Help us out and raise a PR
70
70
{{< / code-panel >}}
71
71
{{< code-panel language="javascript" >}}
72
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
72
+ //Click the link to activate the alert
73
+ await driver.findElement(By.linkText('See an example alert')).click();
74
+
75
+ // Wait for the alert to be displayed
76
+ await driver.wait(until.alertIsPresent());
77
+
78
+ // Store the alert in a variable
79
+ let alert = await driver.switchTo().alert();
80
+
81
+ //Store the alert text in a variable
82
+ let alertText = await alert.getText();
83
+
84
+ //Press the OK button
85
+ await alert.accept();
86
+
87
+ // Note: To use await, the above code should be inside an async function
73
88
{{< / code-panel >}}
74
89
{{< / code-tab >}}
75
90
@@ -134,7 +149,22 @@ alert.Dismiss();
134
149
# We don't have a Ruby code sample yet - Help us out and raise a PR
135
150
{{< / code-panel >}}
136
151
{{< code-panel language="javascript" >}}
137
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
152
+ //Click the link to activate the alert
153
+ await driver.findElement(By.linkText('See an example alert')).click();
154
+
155
+ // Wait for the alert to be displayed
156
+ await driver.wait(until.alertIsPresent());
157
+
158
+ // Store the alert in a variable
159
+ let alert = await driver.switchTo().alert();
160
+
161
+ //Store the alert text in a variable
162
+ let alertText = await alert.getText();
163
+
164
+ //Press the Cancel button
165
+ await alert.dismiss();
166
+
167
+ // Note: To use await, the above code should be inside an async function
138
168
{{< / code-panel >}}
139
169
{{< / code-tab >}}
140
170
@@ -195,6 +225,21 @@ alert.Accept();
195
225
# We don't have a Ruby code sample yet - Help us out and raise a PR
196
226
{{< / code-panel >}}
197
227
{{< code-panel language="javascript" >}}
198
- // We don't have a JavaScript code sample yet - Help us out and raise a PR
228
+ //Click the link to activate the alert
229
+ await driver.findElement(By.linkText('See an example alert')).click();
230
+
231
+ // Wait for the alert to be displayed
232
+ await driver.wait(until.alertIsPresent());
233
+
234
+ // Store the alert in a variable
235
+ let alert = await driver.switchTo().alert();
236
+
237
+ //Type your message
238
+ await alert.sendKeys("Selenium");
239
+
240
+ //Press the OK button
241
+ await alert.accept();
242
+
243
+ //Note: To use await, the above code should be inside an async function
199
244
{{< / code-panel >}}
200
245
{{< / code-tab >}}
0 commit comments