Faced a problem. It is necessary to take data from the file and enter it on the site with a delay between characters (imitation of keyboard input)

string[] file_name = File.ReadAllLines("../FILE/data.txt"); string field1 = file_name[0]; IWebElement credentials_Search = BotSelenium.FindElement(By.Id("username")); foreach (var item in field1.ToCharArray()) { credentials_Search.SendKeys(field1); Thread.Sleep(1500); } 

This code does not work ((it still enters the entire line at 1.5-second intervals).

  • one
    credentials_Search.SendKeys (field1); You enter the entire line for each letter. You need credentials_Search.SendKeys (item); - B. Vandyshev
  • .SendKeys method accepts only string. neither item.ToString nor (string)item works - Igor Storozhuk

1 answer 1

Understood. The .SendKeys method accepts only a string.

 foreach (var item in field1.ToCharArray()) { String cString = item.ToString(); credentials_Search.SendKeys(cString); Thread.Sleep(1500); }