Set value of input instead of sendKeys() - Selenium WebDriver nodejs

后端 未结 8 1935
死守一世寂寞
死守一世寂寞 2020-11-30 03:53

I have a long string to test and sendKeys() takes too long. When I tried to set the value of the text the program crashes. I know the Selenium

8条回答
  •  独厮守ぢ
    2020-11-30 04:13

    Thanks to Andrey-Egorov and this answer, I've managed to do it in C#

    IWebDriver driver = new ChromeDriver();
    IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    string value = (string)js.ExecuteScript("document.getElementById('elementID').setAttribute('value', 'new value for element')");
    

提交回复
热议问题