サーチ…


Python Seleniumはウェブページのスクリーンショットを取得/保存します

from selenium import webdriver

# Create a new cromedriver
driver = webdriver.Chrome()
# Go to www.google.com
driver.get("https://www.google.com")
# Saves a .png file with name my_screenshot_name to the directory that
# you are running the program from.
screenshot_name = "my_screenshot_name.png"
driver.save_screenshot(screenshot_name)

driver.save_screenshotは、スクリーンショットが取られた場合は「true」を返し、そうでなかった場合は「false」を返します。スクリーンショットを保存すると、ヘッドレスブラウザでも機能します。スクリーンショットを別のディレクトリに保存する場合は、コードパスを(コードを実行している場所を基準にして)追加します。例えば:

screenshot_name = "screenshots/my_screenshot_name.png"

スクリーンショットを、pythonが実行されているディレクトリ内のディレクトリ "screenshots"に保存します。

C#TakeScreenshot拡張機能

public static Screenshot TakeScreenshot(this IWebDriver _driver)
{
    return ((ITakesScreenshot)_driver).GetScreenshot();
}

使用例:

driver.TakeScreenshot().SaveAsFile(@"/Test/Test.png",ImageFormat.Png);

Java SeleniumがWebページのスクリーンショットを取得/保存し、レポートに追加する

public void Screenshot() throws Throwable{
    final byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
    scenario.embed(screenshot, "image/png"); // ... and embed it in the report.
    Thread.sleep(1000);
}

代わりに

 public static void captureScreenShot(WebDriver ldriver){

  // Take screenshot and store as a file format
  File src= ((TakesScreenshot)ldriver).getScreenshotAs(OutputType.FILE);
try {
  // now copy the  screenshot to desired location using copyFile method

 FileUtils.copyFile(src, new File("C:/selenium/"+System.currentTimeMillis()+".png"));
   }

catch (IOException e)

{ 
System.out.println(e.getMessage());
  }
}


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow