Skip to content

Instantly share code, notes, and snippets.

@Baneeishaque
Created March 6, 2023 16:21
Show Gist options
  • Save Baneeishaque/b1245578c944dbbe0a8cb516c09b93fa to your computer and use it in GitHub Desktop.
Save Baneeishaque/b1245578c944dbbe0a8cb516c09b93fa to your computer and use it in GitHub Desktop.
C# Selenium Demo
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
using Microsoft.VisualStudio.TestTools.UnitTesting;
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.selenium.dev/selenium/web/web-form.html");
var title = driver.Title;
Assert.AreEqual("Web form", title);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(500);
var textBox = driver.FindElement(By.Name("my-text"));
var submitButton = driver.FindElement(By.TagName("button"));
textBox.SendKeys("Selenium");
submitButton.Click();
var message = driver.FindElement(By.Id("message"));
var value = message.Text;
Assert.AreEqual("Received!", value);
driver.Quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment