我在java中有一个int变量,例如
int height = 10;
我想在 selenium webdriver 的 javascriptexecutor 中使用这个 java int 类型变量。 我尝试了一些方法,但它始终显示错误
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("var test = '${height}';")
或者像这样
jse.executeScript("var test = '<%=height%>';"
如何在selenium webdriver的javascriptexecutor中使用这个int类型变量?
最佳答案
您需要使用+
运算符来实现它。
使用下面的代码:
WebDriver driver=new FirefoxDriver();
driver.get("https://www.google.co.in/");
int height=10;
String script="alert('"+height+" book does not exist');";
JavascriptExecutor js=(JavascriptExecutor)driver;
js.executeScript(script);
关于java - 访问 selenium webdriver javascriptexecutor 中的 java 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32691394/