【问题标题】:Unable to send keys to the text box in Selenium Web Driver C#无法将密钥发送到 Selenium Web Driver C# 中的文本框
【发布时间】:2021-03-31 04:00:01
【问题描述】:

我想将密钥发送到文本区域,但我无法发送密钥。它显示错误为Element must not be hidden, disabled or read-only

我的代码是

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

请告诉我,如何将密钥发送到文本区域。它对我来说是一个障碍。提前致谢

【问题讨论】:

    标签: c# selenium selenium-webdriver textbox


    【解决方案1】:

    异常消息说明了您无法调用SendKeys(...) 的原因。页面上执行的 Selenium 和 JavaScript 之间很可能存在竞争条件。解决方案是在调用SendKeys(...) 之前使用explicit wait

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

    假设是,如果您等到可以单击该元素,则可以通过其他方式与之交互。

    【讨论】:

    猜你喜欢
    • 2019-11-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 1970-01-01
    • 2016-08-05
    • 2020-07-30
    • 2019-11-29
    • 2021-06-27
    相关资源
    最近更新 更多