"Fossies" - the Fresh Open Source Software Archive 
Member "selenium-selenium-4.8.1/dotnet/src/webdriver/Alert.cs" (17 Feb 2023, 2828 Bytes) of package /linux/www/selenium-selenium-4.8.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C# source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "Alert.cs" see the
Fossies "Dox" file reference documentation.
1 // <copyright file="Alert.cs" company="WebDriver Committers">
2 // Licensed to the Software Freedom Conservancy (SFC) under one
3 // or more contributor license agreements. See the NOTICE file
4 // distributed with this work for additional information
5 // regarding copyright ownership. The SFC licenses this file
6 // to you under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 // </copyright>
18
19 using System;
20 using System.Collections.Generic;
21
22 namespace OpenQA.Selenium
23 {
24 /// <summary>
25 /// Defines the interface through which the user can manipulate JavaScript alerts.
26 /// </summary>
27 internal class Alert : IAlert
28 {
29 private WebDriver driver;
30
31 /// <summary>
32 /// Initializes a new instance of the <see cref="Alert"/> class.
33 /// </summary>
34 /// <param name="driver">The <see cref="WebDriver"/> for which the alerts will be managed.</param>
35 public Alert(WebDriver driver)
36 {
37 this.driver = driver;
38 }
39
40 /// <summary>
41 /// Gets the text of the alert.
42 /// </summary>
43 public string Text
44 {
45 get
46 {
47 Response commandResponse = this.driver.InternalExecute(DriverCommand.GetAlertText, null);
48 return commandResponse.Value.ToString();
49 }
50 }
51
52 /// <summary>
53 /// Dismisses the alert.
54 /// </summary>
55 public void Dismiss()
56 {
57 this.driver.InternalExecute(DriverCommand.DismissAlert, null);
58 }
59
60 /// <summary>
61 /// Accepts the alert.
62 /// </summary>
63 public void Accept()
64 {
65 this.driver.InternalExecute(DriverCommand.AcceptAlert, null);
66 }
67
68 /// <summary>
69 /// Sends keys to the alert.
70 /// </summary>
71 /// <param name="keysToSend">The keystrokes to send.</param>
72 public void SendKeys(string keysToSend)
73 {
74 if (keysToSend == null)
75 {
76 throw new ArgumentNullException(nameof(keysToSend), "Keys to send must not be null.");
77 }
78
79 Dictionary<string, object> parameters = new Dictionary<string, object>();
80 parameters.Add("text", keysToSend);
81
82 this.driver.InternalExecute(DriverCommand.SetAlertValue, parameters);
83 }
84 }
85 }