How to use TakeScreenShotOfElement method of Ocaramba.Helpers.TakeScreenShot class

Best Ocaramba code snippet using Ocaramba.Helpers.TakeScreenShot.TakeScreenShotOfElement

TakeScreenShot.cs

Source:TakeScreenShot.cs Github

copy

Full Screen

...106 /// <param name="screenshotName">Name of screenshot.</param>107 /// <returns>Full path to taken screenshot.</returns>108 /// <example>How to use it: <code>109 /// var el = this.Driver.GetElement(this.menu);110 /// var fullPath = TakeScreenShot.TakeScreenShotOfElement(el, Directory.GetCurrentDirectory() + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");111 /// </code></example>112 public static string TakeScreenShotOfElement(IWebElement element, string folder, string screenshotName)113 {114 Logger.Debug("Taking screenhot of element not within iframe");115 return TakeScreenShotOfElement(0, 0, element, folder, screenshotName);116 }117 /// <summary>118 /// Takes screen shot of specific element within iframe.119 /// </summary>120 /// <param name="iframeLocationX">X coordinate of iframe.</param>121 /// <param name="iframeLocationY">Y coordinate of iframe.</param>122 /// <param name="element">Element to take screenshot.</param>123 /// <param name="folder">Folder to save screenshot.</param>124 /// <param name="screenshotName">Name of screenshot.</param>125 /// <returns>Full path to taken screenshot.</returns>126 /// <example>How to use it: <code>127 /// var iFrame = this.Driver.GetElement(this.iframe);128 /// int x = iFrame.Location.X;129 /// int y = iFrame.Location.Y;130 /// this.Driver.SwitchTo().Frame(0);131 /// var el = this.Driver.GetElement(this.elelemtInIFrame);132 /// var fullPath = TakeScreenShot.TakeScreenShotOfElement(x, y, el, Directory.GetCurrentDirectory() + BaseConfiguration.ScreenShotFolder, "MenuOutSideTheIFrame");133 /// </code></example>134 public static string TakeScreenShotOfElement(int iframeLocationX, int iframeLocationY, IWebElement element, string folder, string screenshotName)135 {136 Logger.Debug("Taking screenhot of iframe LocationX:{0} LocationY:{1}", iframeLocationX, iframeLocationY);137 var locationX = iframeLocationX;138 var locationY = iframeLocationY;139 var driver = element.ToDriver();140 var screenshotDriver = (ITakesScreenshot)driver;141 var screenshot = screenshotDriver.GetScreenshot();142 var filePath = Path.Combine(folder, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-fff", CultureInfo.CurrentCulture) + "temporary_fullscreen.png");143 Logger.Debug(CultureInfo.CurrentCulture, "Taking full screenshot {0}", filePath);144 screenshot.SaveAsFile(filePath, ScreenshotImageFormat.Png);145 if (BaseConfiguration.TestBrowser == BrowserType.Chrome)146 {147 locationX = element.Location.X + locationX;148 locationY = element.Location.Y + locationY;...

Full Screen

Full Screen

IFramePage.cs

Source:IFramePage.cs Github

copy

Full Screen

...51 int y = iFrame.Location.Y;52 this.Driver.SwitchTo().Frame(0);53 var el = this.Driver.GetElement(this.elelemtInIFrame);54#if net4755 return TakeScreenShot.TakeScreenShotOfElement(x, y, el, folder, name);56#endif57#if netcoreapp2_258 return "to_be_implemented_in_netcore";59#endif60 }61 public string TakeScreenShotsOfMenu(string folder, string name)62 {63 Logger.Info(CultureInfo.CurrentCulture, "Take Screen Shots");64 var el = this.Driver.GetElement(this.menu);65 //return TakeScreenShot.TakeScreenShotOfElement(el, folder, name);66 return "";67 }68 }69}...

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using Ocaramba.Types;4using NUnit.Framework;5{6 {7 public void TakeScreenShotTest()8 {9 var element = Driver.GetElement(By.Id("someId"));10 var screenShot = new TakeScreenShot();11 screenShot.TakeScreenShotOfElement(element, "someName");12 }13 }14}15using Ocaramba;16using Ocaramba.Helpers;17using Ocaramba.Types;18using NUnit.Framework;19{20 {21 public void TakeScreenShotTest()22 {23 var element = Driver.GetElement(By.Id("someId"));24 var screenShot = new TakeScreenShot();25 screenShot.TakeScreenShotOfElement(element, "someName");26 }27 }28}29using Ocaramba;30using Ocaramba.Helpers;31using Ocaramba.Types;32using NUnit.Framework;33{34 {35 public void TakeScreenShotTest()36 {37 var element = Driver.GetElement(By.Id("someId"));38 var screenShot = new TakeScreenShot();39 screenShot.TakeScreenShotOfElement(element, "someName");40 }41 }42}43using Ocaramba;44using Ocaramba.Helpers;45using Ocaramba.Types;46using NUnit.Framework;47{48 {49 public void TakeScreenShotTest()50 {51 var element = Driver.GetElement(By.Id("someId"));52 var screenShot = new TakeScreenShot();53 screenShot.TakeScreenShotOfElement(element, "someName");54 }55 }56}

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Ocaramba;7using Ocaramba.Helpers;8using OpenQA.Selenium;9using NUnit.Framework;10{11 {12 public void TakeScreenShotOfElement()13 {14 IWebElement element = DriverContext.Driver.FindElement(By.Id("hplogo"));15 TakeScreenShot.TakeScreenShotOfElement(element, "test");16 }17 }18}19using System;20using System.Collections.Generic;21using System.Linq;22using System.Text;23using System.Threading.Tasks;24using Ocaramba;25using Ocaramba.Helpers;26using NUnit.Framework;27{28 {29 public void TakeScreenShotOfElement()30 {31 IWebElement element = DriverContext.Driver.FindElement(By.Id("hplogo"));32 TakeScreenShot.TakeScreenShotOfElement(element, "test");33 }34 }35}36using System;37using System.Collections.Generic;38using System.Linq;39using System.Text;40using System.Threading.Tasks;41using Ocaramba;42using Ocaramba.Helpers;43using NUnit.Framework;44{45 {46 public void TakeScreenShotOfElement()47 {48 IWebElement element = DriverContext.Driver.FindElement(By.Id("hplogo"));49 TakeScreenShot.TakeScreenShotOfElement(element, "test");50 }51 }52}53using System;54using System.Collections.Generic;55using System.Linq;56using System.Text;57using System.Threading.Tasks;58using Ocaramba;59using Ocaramba.Helpers;

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using NUnit.Framework;4using OpenQA.Selenium;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 public void TestMethod1()13 {14 TakeScreenShotOfElement(this.Driver.FindElement(By.Id("hplogo")));15 }16 }17}18at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)19at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)20at OpenQA.Selenium.Remote.RemoteExecuteMethod.Execute[T](IWebDriver driver, Dictionary`2 parameters)21at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)22at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text)23at Ocaramba.Helpers.TakeScreenShot.TakeScreenShotOfElement(IWebDriver driver, IWebElement element, String fileName, String folderName, ImageFormat imageFormat)24at Ocaramba.Helpers.TakeScreenShot.TakeScreenShotOfElement(IWebElement element)25at OcarambaProject1.TestClass1.TestMethod1() in C:\Users\Amit\source\repos\OcarambaProject1\OcarambaProject1\2.cs:line 2226at NUnit.Framework.Internal.Commands.TestMethodCommand.RunTestMethod(TestExecutionContext context)27at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)28at NUnit.Framework.Internal.Commands.TestActionCommand.Execute(TestExecutionContext context)29at NUnit.Framework.Internal.Commands.SetUpTearDownCommand.Execute(TestExecutionContext context)

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using Ocaramba.Types;4using NUnit.Framework;5using System;6{7 {8 public void TakeScreenShotOfElementTest()9 {10 TakeScreenShotOfElement takeScreenShotOfElement = new TakeScreenShotOfElement();11 takeScreenShotOfElement.TakeScreenShotOfElementMethod(DriverContext.Driver, "q", "GoogleSearchBox", "GoogleSearchBox");12 }13 }14}15using Ocaramba;16using Ocaramba.Helpers;17using Ocaramba.Types;18using NUnit.Framework;19using System;20{21 {22 public void TakeScreenShotOfElementTest()23 {24 TakeScreenShotOfElement takeScreenShotOfElement = new TakeScreenShotOfElement();25 takeScreenShotOfElement.TakeScreenShotOfElementMethod(DriverContext.Driver, "q", "GoogleSearchBox", "GoogleSearchBox");26 }27 }28}29using Ocaramba;30using Ocaramba.Helpers;31using Ocaramba.Types;32using NUnit.Framework;33using System;34{35 {36 public void TakeScreenShotOfElementTest()37 {38 TakeScreenShotOfElement takeScreenShotOfElement = new TakeScreenShotOfElement();39 takeScreenShotOfElement.TakeScreenShotOfElementMethod(DriverContext.Driver, "q", "GoogleSearch

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using Ocaramba.Helpers.TakeScreenShot;2using NUnit.Framework;3using OpenQA.Selenium;4using OpenQA.Selenium.Chrome;5using System;6{7 {8 private IWebDriver driver;9 public void SetUp()10 {11 this.driver = new ChromeDriver();12 }13 public void TestTakeScreenshotOfElement()14 {15 var element = this.driver.FindElement(By.Name("q"));16 TakeScreenShotOfElement(this.driver, element, "ScreenshotOfElement");17 }18 public void TearDown()19 {20 this.driver.Quit();21 }22 }23}24using Ocaramba.Helpers.TakeScreenShot;25using NUnit.Framework;26using OpenQA.Selenium;27using OpenQA.Selenium.Chrome;28using System;29{30 {31 private IWebDriver driver;32 public void SetUp()33 {34 this.driver = new ChromeDriver();35 }36 public void TestTakeScreenshotOfElement()37 {38 var element = this.driver.FindElement(By.Name("q"));39 TakeScreenShotOfElement(this.driver, element, "ScreenshotOfElement");40 }41 public void TearDown()42 {43 this.driver.Quit();44 }45 }46}47using Ocaramba.Helpers.TakeScreenShot;48using NUnit.Framework;49using OpenQA.Selenium;50using OpenQA.Selenium.Chrome;51using System;52{53 {54 private IWebDriver driver;55 public void SetUp()56 {57 this.driver = new ChromeDriver();58 }59 public void TestTakeScreenshotOfElement()60 {61 var element = this.driver.FindElement(By.Name("q"));62 TakeScreenShotOfElement(this.driver, element, "

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using Ocaramba.Helpers.TakeScreenShot;2using Ocaramba;3using NUnit.Framework;4using OpenQA.Selenium;5using System.Drawing;6{7 {8 public void TakeScreenShotOfElementTest()9 {10 var screenShot = TakeScreenShotOfElement.TakeScreenShotOfElement(this.Driver, element);11 screenShot.Save(@"C:\Users\Public\Pictures\Sample Screenshots\ElementScreenShot.png");12 }13 public void TakeScreenShotOfElementWithBorderTest()14 {15 var screenShot = TakeScreenShotOfElement.TakeScreenShotOfElement(this.Driver, element, 5, Color.Red);16 screenShot.Save(@"C:\Users\Public\Pictures\Sample Screenshots\ElementScreenShotWithBorder.png");17 }18 }19}20using Ocaramba.Helpers.TakeScreenShot;21using Ocaramba;22using NUnit.Framework;23using OpenQA.Selenium;24using System.Drawing;25{26 {27 public void TakeScreenShotOfElementTest()28 {29 var screenShot = TakeScreenShotOfElement.TakeScreenShotOfElement(this.Driver, element);30 screenShot.Save(@"C:\Users\Public\Pictures\Sample Screenshots\ElementScreenShot.png");31 }32 public void TakeScreenShotOfElementWithBorderTest()33 {34 var screenShot = TakeScreenShotOfElement.TakeScreenShotOfElement(this.Driver, element, 5, Color.Red);35 screenShot.Save(@"C:\Users\Public\Pictures\Sample Screenshots\ElementScreenShotWithBorder.png");36 }37 }38}

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1{2 {3 public static void TakeScreenShotOfElement(IWebElement element, string path, ImageFormat format)4 {5 var elementLocation = element.Location;6 var elementSize = element.Size;7 var screenshot = ((ITakesScreenshot)DriverContext.Driver).GetScreenshot();8 var screenshotImage = screenshot.AsByteArray;9 var screenshotStream = new MemoryStream(screenshotImage);10 var bitmap = new Bitmap(screenshotStream);11 var bitmapCropped = bitmap.Clone(new Rectangle(elementLocation.X, elementLocation.Y, elementSize.Width, elementSize.Height), bitmap.PixelFormat);12 bitmapCropped.Save(path, format);13 }14 }15}16{17 {18 public static void TakeScreenShotOfElement(IWebElement element, string path, ImageFormat format)19 {20 var elementLocation = element.Location;

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using OpenQA.Selenium;4using NUnit.Framework;5using System;6using System.IO;7using System.Reflection;8{9 {10 public void TestMethod()11 {12 IWebElement element = this.Driver.FindElement(By.Id("hplogo"));13 TakeScreenShot.TakeScreenShotOfElement(element, this.Driver, "element", "png");14 }15 }16}

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1using Ocaramba;2using Ocaramba.Helpers;3using OpenQA.Selenium;4using OpenQA.Selenium.Support.UI;5using System;6using System.Collections.Generic;7using System.Linq;8using System.Text;9using System.Threading.Tasks;10{11 {12 public TakeScreenShotOfElement(DriverContext driverContext) : base(driverContext)13 {14 }15 public void TestMethod()16 {17 string path = @"C:\Users\Public\Pictures\Sample Pictures\";18 string fileName = "ElementScreenshot";19 string extension = ".png";20 IWebElement element = this.Driver.FindElement(By.Id("elementId"));21 TakeScreenShot.TakeScreenShotOfElement(this.DriverContext, element, path, fileName, extension);22 }23 }24}25public static void TakeScreenShotOfElement(DriverContext driverContext, IWebElement element, string path, string fileName, string extension)26{27 var screenshot = ((ITakesScreenshot)driverContext.Driver).GetScreenshot();28 var screenshotImage = screenshot.AsByteArray;29 var image = Image.FromStream(new MemoryStream(screenshotImage));30 var cropImage = new Bitmap(element.Size.Width, element.Size.Height);31 var cropGraphics = Graphics.FromImage(cropImage);32 cropGraphics.DrawImage(image, new Rectangle(0, 0, element.Size.Width, element.Size.Height), new Rectangle(element.Location.X, element.Location.Y, element.Size.Width, element.Size.Height), GraphicsUnit.Pixel);33 cropImage.Save(path + fileName + extension, ImageFormat.Png);34}

Full Screen

Full Screen

TakeScreenShotOfElement

Using AI Code Generation

copy

Full Screen

1var takeScreenShotOfElement = new TakeScreenShotOfElement(driver);2takeScreenShotOfElement.TakeScreenShotOfElement(webElement, "C:\\Users\\Test\\Desktop\\element.png");3var takeScreenShotOfElement = new TakeScreenShotOfElement(driver);4takeScreenShotOfElement.TakeScreenShotOfElement(webElement, "C:\\Users\\Test\\Desktop\\element.png");5var takeScreenShotOfElement = new TakeScreenShotOfElement(driver);6takeScreenShotOfElement.TakeScreenShotOfElement(webElement, "C:\\Users\\Test\\Desktop\\element.png");7var takeScreenShotOfPage = new TakeScreenShotOfPage(driver);8takeScreenShotOfPage.TakeScreenShotOfPage("C:\\Users\\Test\\Desktop\\page.png");9var takeScreenShotOfPage = new TakeScreenShotOfPage(driver);10takeScreenShotOfPage.TakeScreenShotOfPage("C:\\Users\\Test\\Desktop\\page.png");11var takeScreenShotOfPage = new TakeScreenShotOfPage(driver);12takeScreenShotOfPage.TakeScreenShotOfPage("C:\\Users\\Test\\Desktop\\page.png");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Ocaramba automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in TakeScreenShot

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful