java selenium (十) 操做瀏覽器

本篇文章介紹selenium 操做瀏覽器 chrome

 

閱讀目錄瀏覽器

 

 

瀏覽器最大化 前進,後退, 刷新

    public static void testBrowser(WebDriver driver) throws Exception
    {
        driver.get("http://www.cnblogs.com/tankxiao");
        Thread.sleep(5000);
        // 瀏覽器最大化
        driver.manage().window().maximize();
        
        driver.navigate().to("http://www.baidu.com");
        // 刷新瀏覽器
        driver.navigate().refresh();
        // 瀏覽器後退
        driver.navigate().back();
        // 瀏覽器前進
        driver.navigate().forward();
        // 瀏覽器退出
        driver.quit();
    }

 

截圖操做

    public static void testScreenShot(WebDriver driver) throws Exception
    {
        driver.get("http://www.baidu.com");
        File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(srcFile, new File("c:\\1.png"));
    }

 

模擬鼠標操做

    public static void rightClickMouse(WebDriver driver)
    {
        driver.get("http://www.baidu.com");
        Actions action = new Actions(driver);
        
        action.contextClick(driver.findElement(By.id("kw"))).perform();    
    }

殺掉Windows瀏覽器進程

    public static void killProcess()
    {
        // kill firefox
        WindowsUtils.tryToKillByName("firefox.exe");
        // kill IE
        WindowsUtils.tryToKillByName("iexplore.exe");
        // kill chrome
        WindowsUtils.tryToKillByName("chrome.exe");
    }

 

 

 

操做cookiecookie

相關文章
相關標籤/搜索