1

I have user-extensions.js that contain the following code of snippet:

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 want to call this function from java code using Selenium RC for a text field ("css=input.text"). How can I call this?

1
  • I have switched to WebDriver from Selenium RC. Method executeScript("") of JavascriptExecutor is used for using JS in Selenium2 (WebDriver) Commented Feb 25, 2013 at 5:04

1 Answer 1

1

From a top of my head you should be able to call your code the following way:

selenium.getEval("Selenium.prototype.doTypeRepeated('input.text', 'some text');");

However, if following suggested approach you should do like

HttpCommandProcessor proc;
proc = new HttpCommandProcessor("localhost", 4444, "*iexplore", "http://google.com/");
Selenium selenium = new DefaultSelenium(proc);
string[] inputParams = {"css=input.text", "Hello World"};
proc.DoCommand("doTypeRepeated", inputParams);

And not forget to start selenium as

java -jar selenium-server.jar -userExtensions user-extensions.js
Sign up to request clarification or add additional context in comments.

1 Comment

The suggested approach is the right one. You don't want to run the doWhatever() function directly, it won't do what you expect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.