selenium webdriver在IE下执行
View Code
public static void main(String[] args) { //webdriver执行IE,IE保护模式全部启用、保护模式全部不启用 System.setProperty("webdriver.ie.driver","D:\\selenium\\IEDriverServer.exe"); DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); WebDriver driver=new InternetExplorerDriver(ieCapabilities); //实例化一个浏览器对象 try { Thread.sleep(500); } catch (InterruptedException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } driver.get("http://www.google.com.hk"); WebElement element =driver.findElement(By.name("q"));//定位元素的name属性为q的元素 element.sendKeys("hello selenium");//搜索"hello selenium" element.submit();//点击搜索 try{ Thread.sleep(3000); }catch(InterruptedException e){ e.printStackTrace(); } System.out.println("Page title is: " + driver.getTitle()); driver.quit(); }