. 1 Package SeleniumTestProject; 2 . 3 Import the java.util.Timer; . 4 Import org.openqa.selenium *. ; . 5 Import org.openqa.selenium.chrome.ChromeDriver; . 6 Import org.yaml.snakeyaml.events.Event.ID; . 7 . 8 public class to Test01 { . 9 protected String WebUrl = "https://caiyun.feixin.10086.cn/"; // store the URL 10 public the WebDriver driver; // define a field driver 11 // initialize browser driver 12 public void InitDriver() { 13 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe"); 14 driver = new ChromeDriver(); 15 driver.get(WebURL); 16 driver.manage().window().maximize(); 17 String title = driver.getTitle(); 18 System.out.print(title); 19 } 20 public void InputBox() { 21 driver.findElement(By.id("account")).sendKeys("15875303116"); 22 } 23 public static void main(String[] args){ 24 Test01 t = new Test01(); 25 t.InitDriver(); 26 27 28 } 29 }
When using the default configuration of the eclipse to compile this code, 21 lines sendKeys error method, suggesting The method sendKeys (CharSequence []) in the type WebElement is not applicable for the arguments (String), later checked, the problem is the compiler right-package project, click Build Path inside the Configure Build Path , change the Java Compiler in the Compiler compliance level to 1.7 (shown below), click after the application can be solved