How to use JavaScript in Selenium RC with Java
I have the following function in user-extensions.js:
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 a Java class and I called the doTypeRepeated
function by following the way:
selenium.getEval("doTypeRepeated(\"txtAppCode\", \"service5\")");
("txtAppCode"
is a textbox and "service5"
is some text to write/type on the textfield)
I got this error:
com.thoughtworks.selenium.SeleniumException:
ERROR: Threw an exception: Object expected"
Can an开发者_StackOverflow社区yone tell me where am I doing wrong?
Selenium mangles the names of extra functions in the Selenium prototype: doFoo becomes simply foo. (Functions starting with is and get are mangled in similar ways.) Try:
selenium.getEval("typeRepeated(\"txtAppCode\", \"service5\")");
精彩评论