selenium-java,启动谷歌浏览器和火狐浏览器

时间:2021-08-13 21:05:19

selenium3.4.0-java,启动谷歌浏览器和火狐浏览器--------------------------------------------------------------------------------

启动谷歌浏览器

@Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.chrome.driver","D:\\Configuration\\chromedriver.exe");//这一步必不可少  
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

启动火狐浏览器

@Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.firefox.driver", "D:\\Configuration\\geckodriver.exe"); 
        System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");   
        WebDriver = new FirefoxDriver();
        WebDriver.manage().window().maximize();
        WebDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

 

selenium3.5.0-java,启动谷歌浏览器和火狐浏览器--------------------------------------------------------------------------------

启动火狐浏览器

    public WebDriver start_Firefox(WebDriver WebDriver){
        System.setProperty("webdriver.firefox.bin", "D:\\firefox\\firefox57\\firefox.exe");
        System.setProperty("webdriver.gecko.driver","D:\\Configuration\\geckodriver-v0.19.1-win64\\geckodriver.exe"); 
        WebDriver = new FirefoxDriver();
        WebDriver.manage().window().maximize();
        WebDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        return WebDriver;
    }