易百教程

31、请编写代码片段以在 WebDriver 中启动 Chrome 浏览器。

参考以下代码实现:

public class ChromeBrowserLaunchDemo {  

    public static void main(String[] args) {  
        //Creating a driver object referencing WebDriver interface  
        WebDriver driver;  

        //Setting the webdriver.chrome.driver property to its executable's location  
        System.setProperty("webdriver.chrome.driver", "/lib/chromeDriver/chromedriver.exe");  

        //Instantiating driver object  
        driver = newChromeDriver();  

        //Using get() method to open a webpage  
        driver.get("http://yiibai.com");  

        //Closing the browser  
        driver.quit();  
    }
}