数日前、私は研究中に自動化していたときに突然考えていました。後で見ることができるように写真を撮ることができるかどうかを考えました。実装方法は実際には難しくありません。結局のところ、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.takescreenshot; Import; org.openqa.selenium.webdriver; Import org.openqa.selenium.firefox.firefoxdriver; import org.openqa.selenium.support.ui.webdriverwait; Import com.sun.jna.platform.fileutils; {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)driver).getScreenshotas(outputType.file); //ファイルの形でキャプチャされるスクリーンショット画像を話します{org.apache.commons.io.fileutils.copyfile(srcfile、new file( "d://screenshot.png")); // copyFile()メソッドを使用して取得したスクリーンショットファイルを保存します} catch(IOException e){// todo auto-feenated catch blocke.printstacktrace();} driver.quit();}}}}他の方法がある場合、私はあなたがそれらを提供し、お互いから学ぶことができることを願っています。
スクリーンショット関数を実装するSelenium WebDriverの上記の例は、私があなたと共有するすべてのコンテンツです。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。