2

Here is my selemium test:

    [Test]
    public void RunStepsTest()
    {
        using (var driver = new InternetExplorerDriver())
        {
            driver.Navigate().GoToUrl(Url);
            ExecuteStep(driver, "start");
            ExecuteStep(driver, "step1");
            ExecuteStep(driver, "step2");
            ExecuteStep(driver, "finish");
        }
    }

    private void ExecuteStep(InternetExplorerDriver driver, string stepName)
    {
        var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        wait.Until(x => ExpectedConditions.ElementIsVisible(By.Id(stepName)));

        var scrrenshot = driver.GetScreenshot();
        scrrenshot.SaveAsFile(Path.Combine(ScreenshotDirectory, stepName + ".jpg"), ScreenshotImageFormat.Jpeg);

        var link = driver.FindElement(By.Id(stepName));
        link.SendKeys(Keys.Enter);
    }

Most of time this test fails on line

        scrrenshot.SaveAsFile(Path.Combine(ScreenshotDirectory, stepName + ".jpg"), ScreenshotImageFormat.Jpeg);

with message "Paramter is not valid". What do I do wrong?

  • Have you had a look at this thread? (http://stackoverflow.com/questions/3422262/take-a-screenshot-with-selenium-webdriver) Not exactly sure if it'll work but you could try like it says in the thread I linked: `File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));` (sorry, code formatting is so bad in comments) – Dillanm Mar 12 '17 at 19:43
  • @Dillanm I havent found TakesScreenshot type in WebDriver or WebDriver.Support dlls. – Александр Сысоев Mar 12 '17 at 20:06
  • Sorry, in .NET it's `ITakesScreenshot` and it's part of the base `WebDriver.dll` library – Dillanm Mar 12 '17 at 20:10

2 Answers2

2

In Internet Explorer driver, it's intended to throw this error .

From Github bug tracking :

Because of the limitations of how the IE driver is forced to work in order to take full-DOM screenshots, screenshots are only supported for browser windows viewing HTML documents. This is entirely as intended by the driver (regardless of the behavior of Chrome or Firefox). The driver is forced by the constraints of the IE browser itself. Accordingly, I'm closing this as "working as intended".

If you are allowed to use other driver, you can try Firefox or Chrome Driver to have screenshot.

Akash KC
  • 16,057
  • 6
  • 39
  • 59
0

Try this code like this:

Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile("e:\\pande", System.Drawing.Imaging.ImageFormat.Jpeg);
P.K.
  • 1,746
  • 6
  • 25
  • 62