简体   繁体   中英

Unable to send keys to the text box in Selenium Web Driver C#

I want to send keys to the text area but I am not able to send the keys. It shows error as Element must not be hidden, disabled or read-only

My code is

IWebElement userid = FamosDriver.WebDriver.FindElement(By.Id("SMSBody"));
                userid.SendKeys("Test");

Please let me know, how to send keys to the text area. its a blocker for me. Thanks in advance

The exception message states why you cannot call SendKeys(...) . Most likely there is a race condition between Selenium and JavaScript executing on the page. The solution is to use an explicit wait before calling SendKeys(...) :

var wait = new WebDriverWait(FamosDriver.WebDriver, TimeSpan.FromSeconds(30));
var userid = wait.Until(ExpectedConditions.ElementToBeClickable(ById("SMSBody")));

userid.SendKeys("test");

The assumption is if you wait until you can click the element, then you can interact with it in other ways.

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