수색…


웹 페이지의 스크린 샷을 저장 / 저장하는 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"

스크린 샷을 파이썬이 실행되는 디렉토리의 "스크린 샷"디렉토리에 저장합니다.

C # TakeScreenshot 확장

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

사용 예 :

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

Java Selenium은 웹 페이지의 스크린 샷을 찍고 저장하고 보고서에 추가합니다.

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