在通過JAVA執行selenium腳本時,出現以下錯誤。Selenium顯示錯誤「類型WebElement中的sendKeys(CharSequence [])方法不適用於參數(字符串)」
錯誤: 「的方法的SendKeys(CharSequence的[])中的類型WebElement是 不適用於參數(字符串)」
我的代碼:
package Pkg_09;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Practice {
public static void main(String[] args) {
WebDriver driver1;
driver1.get("www.google.com");
driver1.findElement(By.id("gs_htif0")).sendKeys("Sachin Tendulkar");
driver1.findElement(By.id("aa")).sendKeys("xx");
driver1.findElement(By.name("btnK")).click();
}
}
請讓我知道是否有什麼我錯過了。
您使用的是什麼版本的Java和Selenium?這看起來像Java的一個老版本,並不瞭解'String'可以分配給'CharSequence'變量。在語義上,'CharSequence ...'會高興地接受no,一個或多個'String'參數。 –
我一直都在傳遞sendKeys(String),它工作正常。 – JeffC
非常感謝您的回覆。我正在使用Java 8和Selenium版本2.39.0。 –