简体   繁体   中英

C# .net Selenium, how to insert a date and time using sendKeys()

I'm doing a project where I need to grab the system date and insert it a txtbox.

I tried following but doesn't seem to work for me, I'm new to C# as well as Selenium, so I might be doing something silly.

query = driver.FindElement(By.Name("txtbox"));
DateTime y = DateTime.Today;
query.SendKeys("y");

How did your code not work? Did it send "y" instead of the date?

var query = driver.FindElement(By.Name("txtbox"));
DateTime y = DateTime.Today;
query.SendKeys(y.ToString()); // you shouldn't send string "y", but the y.ToString()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM