using OpenQA.Selenium; using OpenQA.Selenium.Chrome; // Creating a ChromeDriver instance IWebDriver driver = new ChromeDriver(); // Navigating to the website driver.Navigate().GoToUrl("https://www.example.com"); // Finding an element by its ID and getting its text IWebElement element = driver.FindElement(By.Id("example-id")); string elementText = element.Text; // Closing the driver when finished driver.Quit();
using OpenQA.Selenium; using OpenQA.Selenium.Chrome; // Creating a ChromeDriver instance IWebDriver driver = new ChromeDriver(); // Navigating to the website driver.Navigate().GoToUrl("https://www.example.com"); // Finding and clicking a button IWebElement button = driver.FindElement(By.Id("example-button")); button.Click(); // Filling out a form and submitting it IWebElement input = driver.FindElement(By.Id("example-input")); input.SendKeys("example input"); IWebElement submitButton = driver.FindElement(By.Id("example-submit")); submitButton.Click(); // Closing the driver when finished driver.Quit();Both examples utilize the OpenQA.Selenium.By class to find elements on web pages. This class is part of the OpenQA.Selenium package library.