Welcome to the Question and Answer site for Software Testing Professionals

You can get your queries resolved from Software Testing Professionals.

Ask a Question

Get answers and give answers to questions from other members.

View All Questions

Get votes and earn points to build your reputation in community.

View Hot Questions

BLACK Screenshot with Selenium C# with IE browser - only when there is Exception occured in code.

Open 1 Answers 42 Views
0 1

BLACK Screenshot with Selenium C# with IE browser - ONLY FOR IE browser (Same code working fine with Chrome and Firefox driver , in same condition)

I am working with C# Selenium , I have used below code for Screenshot, the code is working good with all browser like Chrome, IE, Firefox.

But for below condition screenshot method takes black screenshot. :

Condition: If test case faild due to any exception in code, the below code did the black screenshot only for IE browser:

        public void TestCleanup()
            string ssFolder = Path.Combine(Context.TestLogsDir, "Screenshots");
            string idxStr = "0";

            if (Context.DataRow != null)
                var index = Context.DataRow.Table.Rows.IndexOf(Context.DataRow);
                idxStr = index.ToString();

            var screenshotFileName = $"{Path.Combine(ssFolder, Context.TestName)}_{idxStr}.png";

            if (Context.CurrentTestOutcome == UnitTestOutcome.Failed)
                // prep folder if needed
                if (Directory.Exists(ssFolder) == false)

                // Now take a screenshot
                DriverUtils.Instance.WebDriverInstance.TakeScreenshot(screenshotFileName, ImageFormat.Png);
                TestUtils.log.Info($"**SCREENSHOT @ '{screenshotFileName}'**");
            TestUtils.log.Debug($"END TEST: {Context.FullyQualifiedTestClassName}.{Context.TestName}");


 public static void TakeScreenshot(this IWebDriver driver, string FileLocationName, ImageFormat imageFormat)
            ((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(FileLocationName, imageFormat);


Below version of IE and Selenium used:
IEDriver :   <package id="Selenium.WebDriver.IEDriver" version="3.4.0" targetFramework="net452" />

Selenium  : <package id="Selenium.WebDriver" version="3.4.0" targetFramework="net452" />

Exception: Test method DDS.DCRM.Test.Regression.Opportunity.OpportunityNeagtive.UpdateCustomerInboundActionNegative threw exception: 
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:4315/session/df6eda6b-97d1-4bd0-98a0-b06d3de07674/element timed out after 60 seconds. ---> System.Net.WebException: The operation has timed out.

XXX.TestUtils: **SCREENSHOT @ 'C:\Test\TestResults\Deploy 2017-07-13 13_18_06\In\MYPC\Screenshots\UpdateCustomerInboundActionNegative_1.png

Screeshot : Black Image

1 Answer

It looks like you need to change your IEDriverServer.exe. If you are using the 64-bit version, use the 32-bit version. And change 32-bit version to 64-bit version.

Try that and let me know.
answered by (200 points)
commented by (58 points)
Thanks for the answer, I will try this one.
But I did not understand that Why:
a) In case of Test case failure due to code exception: The  screenshot generated black.
b) If test case failed due to Assert : The screen-shot generated as expected.
commented by (192 points)
Are you closing your browser before test cleanup? If that's the case, you need to close and quit your browser in TestCleanup or after it calls TestCleanup.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

We have resolved 1.2k+ Software Testing queries!

Software Testing Board Weekly update

We will send you handpicked questions that you would love to answer.

View previous campaigns.

Top Contributors