How to take screenshot with Selenium Web driver using C#


Selenium web driver provides “Screenshot” class to take the screenshots. Screenshots are really helpful to trace the error after execution of selenium script. It can be saved at the specified location.
Please find below code snippet for it.

using OpenQA.Selenium.Firefox;
using OpenQA.Selenium;
using System.Drawing;
using System.Drawing.Imaging;

Public void Takescreenshot(IWebdriver _driver)
{
Screenshot ss;
            ss=((ITakesScreenshot)_driver).GetScreenshot();
            ss.SaveAsFile("Filename.png",ImageFormat.Png);
}

Comments

  1. What is type Screenshot? Also, it's GetScreenshotAs(OutputType.XXXX)

    Example:
    WebDriver augmentedDriver = new Augmenter().augment(getDriver());

    File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);

    try {
    FileUtils.copyFile(screenshot, new
    File(SCREENSHOT_PATH + "/screenshot.png"));
    } catch (IOException e) {
    e.printStackTrace();
    }

    ReplyDelete
  2. WOW just what I was searching for. Came here by searching
    for windows

    Here is my web-site ... google themes
    My site: google chrome themes

    ReplyDelete
  3. Good day! I know this is kinda off topic however , I'd figured I'd ask.
    Would you be interested in trading links
    or maybe guest authoring a blog post or vice-versa? My blog covers a lot of the
    same subjects as yours and I believe we could greatly benefit from each other.
    If you are interested feel free to send me an email.
    I look forward to hearing from you! Terrific blog by
    the way!

    Stop by my web blog ... advice

    ReplyDelete

Post a Comment

Popular posts from this blog

Hyundai i20 Bluetooth connectivity

Mobile Testing automation with Selenium Webdriver using firefox browser as emulator