Selenium Xunit C#iwebdriver驱动程序= new Chromedriver())不打开浏览器 - 它打开CMD窗口

发布于 2025-01-21 15:40:08 字数 1338 浏览 0 评论 0原文

我有一个硒测试项目,正在努力工作,现在我需要另一个使用硒的项目。因此,我安装了与另一个项目相同的所有Nuget软件包,并开始编写代码,但是在前几行中,我有问题。一旦执行此行,CMD窗口打开(请参见下文),浏览器将打开一秒钟,然后关闭和控制切勿在我程序中的下一行上传递。

using (IWebDriver driver = new ChromeDriver())

我会做什么错?似乎很简单,它在我的另一个项目中起作用。如果我无法弄清楚,也许我只是将大部分代码的另一个项目都肠道化,然后将我的新代码放入副本中。但这不应该很复杂。

回答我在下面得到的第一个问题,这是一个Windows表单应用程序。我最初不知道我需要硒,所以事后我尝试添加它。我希望添加所有可以添加硒/Xunit功能的Nuget软件包。如果那不起作用,我将不得不提出其他事情。我需要去网站,单击一些链接,并认为硒是最简单的方法。

这是使用部分:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Microsoft.Win32;
using System.Diagnostics;
using System.Configuration;
using System.Collections.Specialized;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Management;
using System.Collections.ObjectModel;
using System.Net.Mail;
using System.Net;
using Xunit;

I have a Selenium test project that's up and working find and now I need another project to use Selenium. So I installed all of the same NuGet packages as the other project and started writing code, but right away in the first few lines I have an issue. As soon as it executes this line of code a CMD window opens (see below), a browser opens for a second and then shuts and control never passes on the the next line in my program.

using (IWebDriver driver = new ChromeDriver())

enter image description here

What could I be doing wrong? Seems pretty simple and it works in my other project. If I can't figure this out maybe I'll just gut the other project of most of it's code and put my new code in a copy. But this shouldn't be complicated.

Answering the first question I got below, it's a Windows forms app. I didn't initially know I'd be needing Selenium so I tried adding it after the fact. I was hoping that adding all of the NuGet packages I could add Selenium/xUnit functionality. If that just won't work I'll have to come up with something else. I need to go to a website and click on some links and thought Selenium would be the easiest way to do that.

Here's the Using section:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Edge;
using OpenQA.Selenium.Remote;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using Microsoft.Win32;
using System.Diagnostics;
using System.Configuration;
using System.Collections.Specialized;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Management;
using System.Collections.ObjectModel;
using System.Net.Mail;
using System.Net;
using Xunit;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文