[英]The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)
[英]Selenium shows error "The method sendKeys(CharSequence[]) in the type WebElement is not applicable for the arguments (String)"
通過 JAVA 執行 selenium 腳本時,出現以下錯誤。
錯誤:“WebElement 類型中的方法 sendKeys(CharSequence[]) 不適用於參數 (String)”
我的代碼:
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 版本。 從 1.6 版開始,可以將單個 String 實例作為 CharSequences 傳遞,它是 sendKeys() 方法期望的參數。 但是,如果您使用舊版本或在您的構建腳本中將其指定為源/目標版本,那么您應該傳遞一個 CharSequences 數組作為 sendKeys() 方法的參數。 所以它可以這樣做:
public static void main(String[] args) {
WebDriver driver1;
driver1.get("www.google.com");
driver1.findElement(By.id("gs_htif0")).sendKeys(new String[] {"Sachin Tendulkar"});
driver1.findElement(By.id("aa")).sendKeys(new String[] {"xx"});
driver1.findElement(By.name("btnK")).click();
}
嘗試以下代碼:
driver1.findElement(By.id("aa")).sendKeys(new String[]{"xx"});
我們正在使用帶有 Java 8 的 Eclipse 氧氣版本,它對我們來說運行良好。 我們在 eclipse Luna 和 indigo 上遇到了同樣的問題
當您嘗試將 JAVA 8 與較低版本的 selenium 一起使用時,會發生這種情況,將您的 jar 更改為 selenium 3.0.1 並且一切正常。
如果有人仍然面臨這個問題(Sendkeys 錯誤),請在下面嘗試。
下載“cldc-1.1-java5.0.jar”並將其添加到構建路徑中-->添加外部庫。
下載cldc-1.1-java5.0.jar並進行鏈接解決了該問題。 非常感謝你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.