java如何在selenium中的javaScriptExecutor中发送用户输入
我试图使用javaScriptExecutor在文本框中使用scanner类发送用户输入,但没有获得scanner类捕获的值
Scanner first_captcha = new Scanner(System.in);
System.out.println("Please enter the captcha");
int Captcha = first_captcha.nextInt();
@SuppressWarnings("unused")
WebElement captcha = wait.until(ExpectedConditions.presenceOfElementLocated(By.id("captcha")));
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('captcha').value = Captcha");
/* Value is going to the textbox is "Captcha" but I just wanted to send the value which user provided in the scanner class. */
# 1 楼答案
执行字符串没有整型值的占位符。所以你需要重构jse。根据此语法执行脚本调用
# 2 楼答案
这里
Captcha
是您设置的硬编码字符串。必须将Captch
作为使用Scanner类获取的变量传递使用以下代码:
# 3 楼答案
这应该是有效的: