我已经编写了基本的c#脚本,以在Visual Studio Code中使用Selenium Webdriver调用chrome浏览器。 机器无法访问互联网。我已将nuget硒webdriver / chrome和newtonsoft软件包手动添加到了项目文件中。但是,当我尝试使用OpenQA.Selenium时,它不显示引用(使用intellisense),因此无法调用IWebdriver实例。有人可以指导我为什么尽管添加了webdriver参考但仍无法使用该软件包吗?
下面是csproj文件。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<RestoreSources>../Downloads/pkg-
webdriver/selenium.webdriver/3.141.0</RestoreSources>
<RestoreSources>../Downloads/pkg-
newton/newtonsoft.json/10.0.3</RestoreSources>
<RestoreSources>../Downloads/pkg-
chrome/selenium.chrome.webdriver/2.45.0</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="newtonsoft.json" Version="10.0.3" />
<PackageReference Include="selenium.chrome.webdriver" Version="2.45" />
<PackageReference Include="selenium.webdriver" Version="3.141.0" />
</ItemGroup>
</Project>
下面是脚本:
using System;
using OpenQA.Selenium; --Can't import this package
namespace NAS
{
class Program
{
static IWebdriver driver;
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
dotnet恢复的输出:
Restoring packages for /Users/admin/NAS/NAS.csproj...
Restore completed in 223.99 ms for /Users/admin/NAS/NAS.csproj.
构建和清理:
armagnac:NAS admin$ **dotnet clean**
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 25/02/2019 09:08:41.
1>Project "/Users/admin/NAS/NAS.csproj" on node 1 (Clean target(s)).
1>CoreClean:
Creating directory "obj/Debug/netcoreapp2.2/".
1>Done Building Project "/Users/admin/NAS/NAS.csproj" (Clean target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.51
armagnac:NAS admin$ **dotnet build**
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Restore completed in 33.86 ms for /Users/admin/NAS/NAS.csproj.
NAS -> /Users/admin/NAS/bin/Debug/netcoreapp2.2/NAS.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.23