'How do I take screenshot specific element id in WebView2 without using selenium webdriver? C#
I using selenium webdriver but I don't want the web browser pop-up. How do I take screenshot specific element id in WebView2 without using selenium webdriver?
public void ScreenshotOfElement()
{
IWebDriver driver = new EdgeDriver();
driver.Url = "https://www.hugedomains.com/domain_profile.cfm?"
TakesScreenshot(driver, driver.FindElement(By.ClassName("logo")));
driver.Quit();
}
public void TakesScreenshot(IWebDriver driver, IWebElement element)
{
string fileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".jpg";
Byte[] byteArray = ((ITakesScreenshot)driver).GetScreenshot().AsByteArray;
Bitmap screenshot = new Bitmap(new System.IO.MemoryStream(byteArray));
Rectangle croppedImage = new Rectangle(element.Location.X, element.Location.Y, element.Size.Width, element.Size.Height);
screenshot = screenshot.Clone(croppedImage, screenshot.PixelFormat);
screenshot.Save(String.Format(fileName, ImageFormat.Jpeg));
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
