OpenQA.Selenium.PhantomJS.PhantomJSDriver.GetScreenshot C# (CSharp) Method

GetScreenshot() public method

Gets a Screenshot object representing the image of the page on the screen.
public GetScreenshot ( ) : Screenshot
return Screenshot
        public Screenshot GetScreenshot()
        {
            // Get the screenshot as base64.
            Response screenshotResponse = Execute(DriverCommand.Screenshot, null);
            string base64 = screenshotResponse.Value.ToString();

            // ... and convert it.
            return new Screenshot(base64);
        }

Usage Example

Example #1
0
        private string ExecuteCommand(string url)
        {
            try
            {

                using (var phantom = new PhantomJSDriver())
                {
                    var indexFile = Server.MapPath("~/Scripts/PhantomJS/index.js");
                    var scriptSource = System.IO.File.ReadAllText(indexFile);
                    var script = phantom.ExecutePhantomJS(scriptSource);

                    phantom.Navigate().GoToUrl("https://www.bing.com");

                    phantom.FindElement(By.Id("sb_form_q")).SendKeys("learn2automate");

                    //Click on Search
                    phantom.FindElement(By.Id("sb_form_go")).Click();

                    Screenshot sh = phantom.GetScreenshot();
                    sh.SaveAsFile(@"C:\Temp.jpg", ImageFormat.Png);

                    phantom.Quit();
                }

            }
            catch (Exception ex)
            {
            }

            return string.Empty;
        }
All Usage Examples Of OpenQA.Selenium.PhantomJS.PhantomJSDriver::GetScreenshot