通过 Java 从 Selenium RC 使用 JavaScript
我在 user-extensions.js
中有以下函数,
file:Selenium.prototype.doTypeRepeated = function(locator, text) {
// All locator-strategies are automatically handled by "findElement"
var element = this.page().findElement(locator);
// Create the text to type
var valueToType = text + text;
// Replace the element text with the new text
this.page().replaceText(element, valueToType);
};
我正在将 Selenium RC 与 Java 结合使用。我有 Java 类文件“Services_ProcMethodREOI.java”。我在 Java 文件中使用以下行来调用 javascript 函数 typeRepeated()
:
selenium.getEval("typeRepeated(\"txtAppCode\", \"service5\")");
//txtAppCode is a textfield and service5 is the inputted text on that textfield
当我使用 eclipse 运行 Java 文件时,发现以下错误:
com.thoughtworks.selenium.SeleniumException:错误:抛出一个 异常:需要对象
请建议我如何解决它。
I have the following function in user-extensions.js
file:Selenium.prototype.doTypeRepeated = function(locator, text) {
// All locator-strategies are automatically handled by "findElement"
var element = this.page().findElement(locator);
// Create the text to type
var valueToType = text + text;
// Replace the element text with the new text
this.page().replaceText(element, valueToType);
};
I am using Selenium RC with Java. I have the Java class file "Services_ProcMethodREOI.java". I used the following line in Java file to call the javascript function typeRepeated()
:
selenium.getEval("typeRepeated(\"txtAppCode\", \"service5\")");
//txtAppCode is a textfield and service5 is the inputted text on that textfield
When I ran the Java file using eclipse, I found the following error:
com.thoughtworks.selenium.SeleniumException: ERROR: Threw an
exception: Object expected
Pls suggest me how can I solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 doCommand 方法来触发您创建的新命令。 http://seleniumhq.org/ 有很好的文档docs/08_user_extensions.html#using-user-extensions-with-selenium-rc
You need to use the doCommand method to fire off your new command that you have created. THere is good documentation at http://seleniumhq.org/docs/08_user_extensions.html#using-user-extensions-with-selenium-rc