खोज…


पायथन सेलेनियम वेबपेज का स्क्रीनशॉट लें / सेव करें

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)

अगर स्क्रीनशॉट लिया गया था, और 'असत्य' नहीं था, तो ड्राइवर। save_screenshot 'सही' लौटाएगा। स्‍क्रीनशॉट सेव करना हेडलेस ब्राउजर के साथ भी काम करता है। यदि आप किसी अलग निर्देशिका में स्क्रीनशॉट को सहेजना चाहते हैं, तो बस फ़ाइलपथ (जहाँ आप कोड चला रहे हैं, उसके सापेक्ष) जोड़ें। उदाहरण के लिए:

screenshot_name = "screenshots/my_screenshot_name.png"

क्या निर्देशिका "स्क्रीनशॉट" में स्क्रीनशॉट को उस निर्देशिका के अंदर सहेज देगा जिसे अजगर से चलाया जा रहा है।

C # टेकस्क्रीशॉट एक्सटेंशन

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

उपयोग उदाहरण:

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

जावा सेलेनियम वेबपेज का स्क्रीनशॉट लें / सेव करें और रिपोर्ट में जोड़ें

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