在没有 GUI 的情况下在 Ubuntu 上运行 Selenium HostedService

时间:2021-06-15 01:48:27

标签: selenium ubuntu selenium-chromedriver core

我正在开发一个简单的 .net 核心 HostedService 应用程序,该应用程序使用 Selenium 与网站进行交互。当我在 Windows 机器上进行本地测试时,一切正常。但是一旦我向驱动程序添加“--healess”参数:

            var options = new ChromeOptions();
            options.AddArgument("--headless");
            options.AddArgument("--no-sandbox");
            options.AddArgument("--disable-dev-shm-usage");
            ChromeDriver driver = new ChromeDriver (Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);

我开始在所有“FindElement”调用中收到 NullReferenceException。

driver.FindElementByClassName("MenuItems").Click();

将我的应用程序部署到没有 GUI 的 ubuntu 服务器时也是如此。有没有办法让这个应用程序在没有 GIU 的 Linux 服务器上运行? 我想要的是在我的服务器上将 HostedService 应用作为作业运行,以便它可以按照预定义的时间表与网站进行交互。

0 个答案:

没有答案
相关问题