며칠 전, 나는 연구 중에 자동화 할 때 갑자기 아이디어를 얻었고, 나중에 볼 수 있도록 사진을 찍을 수 있는지 생각했습니다. 구현 방법은 실제로 어렵지 않습니다. 결국 Selenium Webdriver는 스크린 샷 기능인 Takesscreenshot 인터페이스 함수를 제공했습니다 (영어로는 스크린 샷을 찍는 것을 의미합니다).
말도 안되는 말을하지 말고 코드를 업로드하십시오
패키지 com.wch; import java.io.file; import java.io.ioexception; import org.junit.after; import org.junit.before; import org.junit.test; import org.openqa.selenium.outputtype; import org.openqa.selenium.takesscreenshot; import org.openqa.selenium.webdriver; import org.openqa.selenium.firefox.firefoxdriver; import org.openqa.selenium.support.ui.webdriverwait; import com.sun.jna.jna.jna.platform.fileutils; public static void main (strest) {system.setProperty ( "webdriver.firefox.bin", "d : // program files (x86) // mozilla firefox // firefox.exe"); webdriver driver = new Firefoxdriver (); driver.get ( "http://www.baidu.com"); 파일 srcfile = ((takesscreenshot) 드라이버) .getScreenshotas (outputtype.file); // 파일 형식으로 캡처 할 스크린 샷 이미지 {org.apache.commons.io.fileutils.copyfile (srcfile, 새 파일 ( "d : //screenshot.png"); // copyfile () 메소드를 사용하여 얻은 스크린 샷 파일을 저장} catch (ioexception e) {// todo 자동 생성 된 Catch Blocke.printstackTrace ();} driver.quit ();}}다른 방법이 있다면, 나는 당신이 그들을 제공하고 서로에게서 배울 수 있기를 바랍니다.
스크린 샷 기능을 구현하는 Selenium Webdriver의 위의 예는 내가 공유하는 모든 컨텐츠입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.