@Test public void testElementByID() { //通过JS获取页面元素 driver.get(url); driver.manage().window().maximize(); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } String js = "var user_input = document.getElementById("su").value;return user_input;"; String content=(String) ((JavascriptExecutor)driver).executeScript(js); System.out.println(content); Assert.assertEquals( "百度一下", content); driver.quit(); }