2011-02-15 59 views
2

我在用戶extensions.js下面的函數使用JavaScript:如何硒RC與Java

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

我使用硒RC與Java。我有一個Java類和我通過以下方式稱爲doTypeRepeated功能:

selenium.getEval("doTypeRepeated(\"txtAppCode\", \"service5\")"); 

"txtAppCode"是一個文本框和"service5"是一些文本來寫/類型的文本框)

我得到這個錯誤:

com.thoughtworks.selenium.SeleniumException: 
    ERROR: Threw an exception: Object expected" 

有誰能告訴我我在哪裏做錯了嗎?

+0

我已將Selenium RC的測試轉換爲WebDriver。 executeScript()取代Selenium 2(WebDriver)中的getEval() – 2013-02-26 07:13:57

回答

1

Selenium在Selenium原型中增加了額外函數的名字:doFoo變成了簡單的foo。 (以is和get開始的函數以類似的方式被破壞。)嘗試:

selenium.getEval("typeRepeated(\"txtAppCode\", \"service5\")"); 
+0

感謝您的回覆。我嘗試通過使用selenium.getEval(「typeRepeated(\」txtAppCode \「,\」service5 \「)」); 但是我發現了以下錯誤: – 2011-02-23 09:06:37