Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added csharp code for alert #2084

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,84 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Collections.Generic;
using OpenQA.Selenium.Support.UI;

namespace SeleniumDocs.Interactions
{
[TestClass]
public class AlertsTest : BaseTest
public class AlertsTest
{
[TestMethod]
public void TestAlertCommands()
{
WebDriver driver = new ChromeDriver();
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);

// Navigate to Url
driver.Url= "https://www.selenium.dev/documentation/webdriver/interactions/alerts/";

// Simple Alert
// Click the link to activate the alert
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
// Execute JS for alert
js.ExecuteScript("alert('Sample Alert');");
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
// Wait for the alert to be displayed and store it in a variable
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.AlertIsPresent());

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 46 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context
IAlert alert = driver.SwitchTo().Alert();
// Store the alert text in a variable and verify it
string text = alert.Text;
Assert.AreEqual(text, "Sample Alert");
alert.Accept();


// Confirm Alert
// Execute JS for confirm
js.ExecuteScript("confirm('Are you sure?');");
// Wait for the alert to be displayed
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.AlertIsPresent());

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 58 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context
alert = driver.SwitchTo().Alert();
// Store the alert text in a variable and verify it
text = alert.Text;
Assert.AreEqual(text, "Are you sure?");
// Press the Cancel button
alert.Dismiss();

// Prompt Alert
// Execute JS for prompt
js.ExecuteScript("prompt('What is your name?');");
// Wait for the alert to be displayed
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.AlertIsPresent());

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (ubuntu, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (macos, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, nightly)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context

Check failure on line 70 in examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs

View workflow job for this annotation

GitHub Actions / tests (windows, stable)

The name 'SeleniumExtras' does not exist in the current context
alert = driver.SwitchTo().Alert();
// Store the alert text in a variable and verify it
text = alert.Text;
Assert.AreEqual(text, "What is your name?");
// Type your message
alert.SendKeys("Selenium");
// Press the OK button
alert.Accept();

//quitting driver
driver.Quit(); //close all windows
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,10 @@ alerts.
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L12-L18" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See an example alert")).Click();

//Wait for the alert to be displayed and store it in a variable
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());

//Store the alert text in a variable
string text = alert.Text;
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L39-L51" >}}
{{< /tab >}}

//Press the OK button
alert.Accept();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}}
{{< /tab >}}
Expand Down Expand Up @@ -86,22 +77,10 @@ This example also shows a different approach to storing an alert:
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L26-L32" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample confirm")).Click();

//Wait for the alert to be displayed
wait.Until(ExpectedConditions.AlertIsPresent());

//Store the alert in a variable
IAlert alert = driver.SwitchTo().Alert();

//Store the alert in a variable for reuse
string text = alert.Text;
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L54-L64" >}}
{{< /tab >}}

//Press the Cancel button
alert.Dismiss();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}}
{{< /tab >}}
Expand Down Expand Up @@ -146,19 +125,11 @@ See a sample prompt</a>.
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L40-L47" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample prompt")).Click();

//Wait for the alert to be displayed and store it in a variable
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L66-L78" >}}
{{< /tab >}}

//Type your message
alert.SendKeys("Selenium");

//Press the OK button
alert.Accept();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}}
{{< /tab >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,9 @@ WebDriverはポップアップからテキストを取得し、これらのア
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L12-L18" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See an example alert")).Click();

//Wait for the alert to be displayed and store it in a variable
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());

//Store the alert text in a variable
string text = alert.Text;

//Press the OK button
alert.Accept();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L39-L51" >}}
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}}
{{< /tab >}}
Expand Down Expand Up @@ -79,22 +69,9 @@ alert.accept()
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L26-L32" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample confirm")).Click();

//Wait for the alert to be displayed
wait.Until(ExpectedConditions.AlertIsPresent());

//Store the alert in a variable
IAlert alert = driver.SwitchTo().Alert();

//Store the alert in a variable for reuse
string text = alert.Text;

//Press the Cancel button
alert.Dismiss();
{{< /tab >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L54-L64" >}}
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}}
{{< /tab >}}
Expand Down Expand Up @@ -136,19 +113,10 @@ alert.dismiss()
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L40-L47" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample prompt")).Click();

//Wait for the alert to be displayed and store it in a variable
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());

//Type your message
alert.SendKeys("Selenium");
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L66-L78" >}}
{{< /tab >}}

//Press the OK button
alert.Accept();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}}
{{< /tab >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ alertas.
{{< tab header="Python" text=true >}}
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L12-L18" >}}
{{< /tab >}}

{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L39-L51" >}}
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}}
{{< /tab >}}
Expand Down Expand Up @@ -70,24 +72,8 @@ Este exemplo também mostra uma abordagem diferente para armazenar um alerta:
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L26-L32" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample confirm")).Click();

//Wait for the alert to be displayed
wait.Until(ExpectedConditions.AlertIsPresent());

//Store the alert in a variable
IAlert alert = driver.SwitchTo().Alert();

//Store the alert in a variable for reuse
string text = alert.Text;

//Press the Cancel button
alert.Dismiss();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}}
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L54-L64" >}}
{{< /tab >}}
{{< tab header="JavaScript" text=true >}}
{{< gh-codeblock path="examples/javascript/test/interactions/alert.spec.js#L30-L32" >}}
Expand Down Expand Up @@ -129,19 +115,11 @@ Veja um exemplo de prompt </a>.
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L40-L47" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample prompt")).Click();

//Wait for the alert to be displayed and store it in a variable
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L66-L78" >}}
{{< /tab >}}

//Type your message
alert.SendKeys("Selenium");

//Press the OK button
alert.Accept();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}}
{{< /tab >}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,10 @@ WebDriver可以从弹窗获取文本并接受或关闭这些警告.
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L12-L18" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See an example alert")).Click();

//Wait for the alert to be displayed and store it in a variable
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());

//Store the alert text in a variable
string text = alert.Text;
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L39-L51" >}}
{{< /tab >}}

//Press the OK button
alert.Accept();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L15-L22" >}}
{{< /tab >}}
Expand Down Expand Up @@ -75,22 +66,10 @@ alert.accept()
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L26-L32" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample confirm")).Click();

//Wait for the alert to be displayed
wait.Until(ExpectedConditions.AlertIsPresent());

//Store the alert in a variable
IAlert alert = driver.SwitchTo().Alert();

//Store the alert in a variable for reuse
string text = alert.Text;
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L54-L64" >}}
{{< /tab >}}

//Press the Cancel button
alert.Dismiss();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L28-L35" >}}
{{< /tab >}}
Expand Down Expand Up @@ -131,19 +110,11 @@ alert.dismiss()
{{< gh-codeblock path="examples/python/tests/interactions/test_alerts.py#L40-L47" >}}
{{< /tab >}}

{{< tab header="CSharp" >}}
//Click the link to activate the alert
driver.FindElement(By.LinkText("See a sample prompt")).Click();

//Wait for the alert to be displayed and store it in a variable
IAlert alert = wait.Until(ExpectedConditions.AlertIsPresent());
{{< tab header="CSharp" text=true >}}
{{< gh-codeblock path="examples/dotnet/SeleniumDocs/Interactions/AlertsTest.cs#L66-L78" >}}
{{< /tab >}}

//Type your message
alert.SendKeys("Selenium");

//Press the OK button
alert.Accept();
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/interactions/alerts_spec.rb#L41-L48" >}}
{{< /tab >}}
Expand Down
Loading