我最近从selenium RC更改为WebDriver可以建议getEval函数的最佳替代方案吗?

时间:2014-01-30 07:01:41

标签: selenium selenium-rc

return super.getEval(script);

我想在执行java脚本后返回字符串

(String)((JavascriptExecutor)this).executeScript(jsExpression)

1 个答案:

答案 0 :(得分:0)

尝试使用它:

public void trigger(String script, WebElement element) {
    ((JavascriptExecutor) driver).executeScript(script, element);
}

public Object trigger(String script) {
    return ((JavascriptExecutor) driver).executeScript(script);
}

使用它:

 //get value
 String script = "return document.getElementsByTagName('input')[0].value;";
 //get text
 String script = "return document.getElementsByTagName('p')[0].innerHTML;";
 Object elementValue = trigger(script);
 String value = (String) elementValue;

 //use some element
 WebElement element = driver.findElement(By.id("someId"));
 trigger("arguments[0].click();", element);