简体   繁体   中英

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 anyone 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\")");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM