Skip to content

Instantly share code, notes, and snippets.

@bharathmuddada
Created August 7, 2022 10:37
Show Gist options
  • Save bharathmuddada/7ac69a2c002b9d8eb7f1b4a14dbce634 to your computer and use it in GitHub Desktop.
Save bharathmuddada/7ac69a2c002b9d8eb7f1b4a14dbce634 to your computer and use it in GitHub Desktop.
C# Selenium Program to copy paste text
public class SeleniumSample {
public static void Main(string[] args) {
new DriverManager().SetUpDriver(new ChromeConfig());
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.google.com/");
driver.Manage().Window.Maximize();
var search_field = driver.FindElement(By.Name("q"));
search_field.SendKeys("Selenium");
Actions actions = new Actions(driver);
//To copy text from the search input field
actions.DoubleClick(search_field).KeyDown(Keys.Control).SendKeys("c").Perform();
//To Save text in the search input field
actions.Click(search_field).KeyDown(Keys.Space).KeyDown(Keys.Command).SendKeys("v").SendKeys(Keys.Enter).Perform();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment