我们有一个即插即用设备,可以将数据发送到网页上的div元素。 我通过使用IWebElement.SendKeys()方法将数据发送到div元素来自动化它。但是发送2000个字符需要6秒钟。
尝试使用IJavaScriptExecutor.ExecuteScript方法设置innerHTML,如此处所述 Sending Keys into <div> tag with Selenium Webdriver on Edge
尝试使用ExecuteScript设置值属性,但没有运气。
该方法显示我在浏览器上发送的文本但不模拟sendKeys方法。
有没有其他方法可以传递数据而不浪费6秒?
答案 0 :(得分:0)
如果您使用IJavaScriptExecutor
,则需要设置value
属性,而不是内部html。顺便说一句IWebDriver
内置了ExecuteScript
方法,无需使用IJavaScriptExecutor
IWebElement inputField = driver.FindElement(...);
string value = "...";
driver.ExecuteJavaScript<string>("arguments[0].setAttribute('value', arguments[1])", inputField, value);