Buscar..


Python Selenium tomar / guardar captura de pantalla de la página web

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 devolverá 'verdadero' si se tomó la captura de pantalla, y 'falso' si no lo fue. Guardar capturas de pantalla también funciona con navegadores sin cabeza. Si desea guardar una captura de pantalla en un directorio diferente, simplemente agregue la ruta de archivo (relativa a la ubicación desde donde se ejecuta el código). Por ejemplo:

screenshot_name = "screenshots/my_screenshot_name.png"

Guardará la captura de pantalla en el directorio "screenshots" dentro del directorio desde donde se ejecuta python.

Extensión C # TakeScreenshot

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

Ejemplo de uso:

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

Captura de pantalla de captura / guardado de Java Selenium de la página web y agregue en el informe

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);
}

Alternativamente

 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
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow