WebDriver??????????
???????????? ???????[ 2015/2/13 16:23:50 ] ????????WebDriver ??????????
???????? ???????? ?????н??
package com.example.tests;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Selenium2 {
@Test
public void testTakesScreenshot() {
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.baidu.com");
try {
File srcFile = ((TakesScreenshot)driver).
getScreenshotAs(OutputType.FILE);
FileUtils.copyFile
(srcFile??new File("d:\screenshot.png"));
} catch (Exception e) {
e.printStackTrace();
}
driver.close();
}
}
????TakesScreenshot???????getScreenshotAs()????????????????????????У??????????OutputType.FILE????????????getScreenshoAs()???????????????????????????????????
?????????????RemoteWebDriver() ?????????????
???????????selenium java -jar selenium-server-standalone-2.25.0.jar
package com.example.tests;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.*;
public class Selenium2 {
@Test
public void testRemoteWebDriverScreenShot() {
//????????????
DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
WebDriver driver = null;
try {
driver = new RemoteWebDriver( //?????localhost??????
new URL("http://localhost:4444/wd/hub")?? capability);
} catch (MalformedURLException e) {
e.printStackTrace();
}
driver.get("http://www.sina.com.cn");
//??????????н??
driver = new Augmenter().augment(driver);
File scrFile =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile?? new File("D:\screenshot.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11