我每个月都会在一些网站页面上运行下面的程序(你知道的,selenium测试等等),然后我会把输出的截图上传到某个地方.

由于某种原因,这一次突然程序抛出了这个错误,并提示我运行上个月的最后一个成功构建.我 Select 了它,并获得了我想要的屏幕截图,但我不想每次都使用上次成功的构建,为什么在没有完成代码更改的情况下,现在突然抛出这个错误?

Error   CS0103  The name 'ScreenshotImageFormat' does not exist in the current context

Program.cs

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System.IO;
using System.Configuration;

namespace SSL_Labs
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] domains;

            // TODO: Config
            domains = new string[] { "website1.com", "website2.com"};

            foreach (string d in domains) { 
                GenerateSslLabsReport(d);
            }
        }
        
        private static void GenerateSslLabsReport(string domain)
        {
            IWebDriver driver;
            IWebElement hostName;
            IWebElement hideResults;
            IWebElement submit;
            WebDriverWait waitForReport;
            ITakesScreenshot screenshot;

            string outputBasePath = "C:\\Users\\User\\Documents\\SSL\\";
            string timestamp = DateTime.Now.ToString("yyyy-MM");
            string subDirectory = "Output_" + timestamp;
            string outputPath = Path.Combine(outputBasePath, subDirectory) + "\\";
            Directory.CreateDirectory(outputPath);
            string createdDirectoryPath = outputPath;

            /* Uncomment below code if you want to test directory path is correct
            string fileName = "sample.txt";
            string filePath = Path.Combine(createdDirectoryPath, fileName);
            File.WriteAllText(filePath, "This is a sample text file.");

            if (File.Exists(filePath))
            {
                Console.WriteLine("File created successfully.");
            }
            else
            {
                Console.WriteLine("File not created.");
            }
            */

            Console.WriteLine("Starting SSL Labs reporting ...");

            driver = null;

            try
            {
                driver = new ChromeDriver();
                driver.Manage().Window.Maximize();
                driver.Url = "https://www.ssllabs.com/ssltest/";

                hideResults = driver.FindElement(By.XPath(".//*[@id='hideResults']"));
                hideResults.Click();

                hostName = driver.FindElement(By.XPath(".//*[@name='d']"));
                hostName.SendKeys(domain);
                
                submit = driver.FindElement(By.XPath(".//*[@type='submit']"));
                submit.Click();

                waitForReport = new WebDriverWait(driver, new TimeSpan(0, 0, 120));
                waitForReport.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='rating']")));

                // TODO: Config
                File.WriteAllText(string.Format(createdDirectoryPath + "{0}.html", domain), driver.PageSource.Replace("<head>", "<head><base href=\"https://www.ssllabs.com/\" target=\"_blank\"></base"));

                screenshot = (ITakesScreenshot)driver;
            
                screenshot.GetScreenshot().SaveAsFile(string.Format(createdDirectoryPath + "{0}.png", domain), ScreenshotImageFormat.Png);

                driver.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error processing domain: {domain}");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                if (driver != null) driver.Dispose();
            }
        }
    }
}

我所做的唯一一件事就是像我通常每个月做的那样更新Selify驱动程序,这样它就不会与新的Chrome更新冲突.

updated drivers

推荐答案

尽量不要传递ScreenhotImageFormat.Png

I mean
screenshot.GetScreenshot().SaveAsFile(string.Format(createdDirectoryPath + "{0}.png", domain));

Csharp相关问答推荐

MongoDB实体框架核心:表达必须可写

IComponition.获取IReadOnlyCollection的返回默认属性值

MongoDB将JS查询转换为C#的问题

一小时后,自定义缓存停止在App Insight中保存

如何在Visual Studio代码中更改大括号模式{},用于C#语言

使用HttpResponseMessage中的嵌套列表初始化JSON

当前的文化决定了错误的文化

每个http请求需要60秒,为什么?

当我没有此令牌时,为什么语法报告EOF错误?

ASP.NET Core MVC将值从视图传递到控制器时出现问题

委托RequestDelegate不带2个参数-ASP.NET Core 8最小API

当我将`ConcurentDictionary`转换为`IDictionary`时,出现了奇怪的并发行为

实体框架-IsRequired()与OnDelete()

如何从Entity Framework Core中填充ListIInterface

是否可以从IQueryable T中获取一个IdentyEntry T>

将J数组转换为列表,只保留一个嵌套的JToken

如何从原始图像到新创建的图像获得相同的特定 colored颜色 ,并且具有相同的 colored颜色 量和相同的宽度和高度?

除非首先访问使用的终结点,否则本地API上的终结点不起作用

如何在flutter dart中使用publicKey.xml文件进行rsa加密,我遇到了问题Exception:Could not parse BigInt

MudRadioGroup不切换