1

我在 selenium 中测试一个 Extjs 应用程序,我需要运行一个脚本来设置组合框的值。我试过getEval用目标命令

var combo=Ext.getCmp('combobox name'); combo.setValue('4'); combo.fireEvent('select');

但我有以下错误: [error] Threw an exception: Ext is not defined

谁能帮帮我?

4

1 回答 1

0

jsExecutor 呢?

    JavascriptExecutor js = (JavascriptExecutor) driver;
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("var combo=Ext.getCmp('combobox name');");
    stringBuilder.append("combo.setValue('4');");
    stringBuilder.append("combo.fireEvent('select');");
    js.executeScript(stringBuilder.toString());

如果抛出任何其他异常 - 尝试在您工作的 IDE 中逐步调试

另请参阅从您测试部分执行 JavaScript :

JavaScript 在执行 selenium 不直接支持的应用程序时非常方便。selenium API 的 getEval 方法可用于从 selenium RC 执行 JavaScript。

public static String[] getAllCheckboxIds () {
             String script = "var inputId  = new Array();";// Create array in java script.
             script += "var cnt = 0;"; // Counter for check box ids.
             script += "var inputFields  = new Array();"; // Create array in java script.
             script += "inputFields = window.document.getElementsByTagName('input');"; // Collect input elements.
             script += "for(var i=0; i<inputFields.length; i++) {"; // Loop through the collected elements.
             script += "if(inputFields[i].id !=null " +
             "&& inputFields[i].id !='undefined' " +
             "&& inputFields[i].getAttribute('type') == 'checkbox') {"; // If input field is of type check box and input id is not null.
             script += "inputId[cnt]=inputFields[i].id ;" + // Save check box id to inputId array.
             "cnt++;" + // increment the counter.
             "}" + // end of if.
             "}"; // end of for.
             script += "inputId.toString();" ;// Convert array in to string.
             String[] checkboxIds = selenium.getEval(script).split(","); // Split the string.
             return checkboxIds;
 }

或另一个例子:

selenium.getEval("window.document.images.length;");

希望这可以帮助你

于 2012-10-24T12:53:59.433 回答