Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java从Selenium RC调用JavaScript函数_Java_Javascript_Selenium Rc - Fatal编程技术网

如何使用Java从Selenium RC调用JavaScript函数

如何使用Java从Selenium RC调用JavaScript函数,java,javascript,selenium-rc,Java,Javascript,Selenium Rc,我有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 typ

我有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);
};

我想使用Selenium RC从java代码中调用这个函数作为文本字段(“css=input.text”)。我该怎么称呼它呢?

从我的头顶上看,你应该可以用以下方式来称呼你的代码:

selenium.getEval("Selenium.prototype.doTypeRepeated('input.text', 'some text');");
然而,如果你喜欢下面的方法

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);
别忘了把selenium作为

java -jar selenium-server.jar -userExtensions user-extensions.js

在我看来,您应该能够通过以下方式调用代码:

selenium.getEval("Selenium.prototype.doTypeRepeated('input.text', 'some text');");
然而,如果你喜欢下面的方法

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);
别忘了把selenium作为

java -jar selenium-server.jar -userExtensions user-extensions.js

建议的方法是正确的。如果您不想直接运行doWhatever()函数,它将不会执行您所期望的操作。建议的方法是正确的。您不想直接运行doWhatever()函数,它不会实现您所期望的功能。我已从Selenium RC切换到WebDriver。JavascriptExecutor的方法executeScript(“”)用于在Selenium2(WebDriver)中使用JS,我已从SeleniumRC切换到WebDriver。JavascriptExecutor的方法executeScript(“”)用于在Selenium2(WebDriver)中使用JS