using File_Watcher.Models; #if Selenium using OpenQA.Selenium; using OpenQA.Selenium.Edge; #endif namespace File_Watcher.Helpers; internal static partial class SeleniumHelper { // // internal static bool HyperTextMarkupLanguageToPortableNetworkGraphics(AppSettings appSettings, ILogger logger) { if (!string.IsNullOrEmpty(appSettings.SeleniumConfiguration.UniformResourceLocator)) logger.LogInformation("This helper is disabled!"); #if Selenium EdgeOptions edgeOptions = new(); foreach (string edgeOption in appSettings.SeleniumConfiguration.EdgeOptions) edgeOptions.AddArgument(edgeOption); EdgeDriver edgeDriver = new(edgeOptions); string outputFile = Path.Combine(appSettings.SeleniumConfiguration.DestinationDirectory, $"{DateTime.Now:yyyy-MM-dd;HH-mi-ss-fff}.png"); try { edgeDriver.Navigate().GoToUrl(appSettings.SeleniumConfiguration.UniformResourceLocator); #pragma warning disable CS8602, CS8604 int fullWidth = int.Parse(edgeDriver.ExecuteScript("return document.body.parentNode.scrollWidth").ToString()); int fullHeight = int.Parse(edgeDriver.ExecuteScript("return document.body.parentNode.scrollHeight").ToString()); #pragma warning restore CS8602, CS8604 edgeDriver.Manage().Window.Size = new(fullWidth, fullHeight); Screenshot screenshot = edgeDriver.GetScreenshot(); screenshot.SaveAsFile(outputFile); } catch (Exception ex) { logger.LogError(ex, ex.Message); } edgeDriver.Close(); #endif return true; } }