javascript 如何在 Selenium WebDriver 中使用 JavasSript 在文本字段/框中输入值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11857586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 14:34:40 来源:igfitidea点击:
How to input a value in a text field/box by using JavasSript in Selenium WebDriver
提问by
I am using WebDriver with java. I want to input some text in a text field by using JavaScript. How can I do that?
我正在使用带有 Java 的 WebDriver。我想使用 JavaScript 在文本字段中输入一些文本。我怎样才能做到这一点?
采纳答案by Ripon Al Wasim
Considering to input a text in Google search textfield, the following code should work:
考虑在 Google 搜索文本字段中输入文本,以下代码应该可以工作:
WebDriver driver = new FirefoxDriver();
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('gbqfq').value = 'Ripon Al Wasim';");