简体   繁体   English

Visual Studio 2013,JavaScriptExecutor使用指令

[英]Visual Studio 2013, JavaScriptExecutor using directive

Ok, this is stupid, and I'm obviously blind and dumb. 好的,这很愚蠢,我显然是瞎子又傻。 But here goes: 但是这里:

I'v trying to use JavaScriptExecutor in C#, Visual Studio. 我正在尝试在C#,Visual Studio中使用JavaScriptExecutor。 However, I cannot find out which "using" directive to put at the top of the file for it to work. 但是,我无法找出将哪个“ using”指令放在文件顶部以使其正常工作。 And nowhere on the web can I find ANY help on this, which makes me suspect that it's so idiotially simple that no one even bothers mentioning it. 而且在网络上我找不到任何帮助,这使我怀疑它是如此地简单,以至于没人理会它。 Anywhere. 无处不在。 Never. 决不。

So, I need to use JavaScriptExecutor - in a unit test using Selenium. 因此,我需要使用JavaScriptExecutor-在使用Selenium的单元测试中。 So I need to put... 所以我需要放...

using System.web;
using ..... ?;

at the top of my class file? 在我班级文件的顶部?

Download and install NuGet Package Manager using Tools -> Extension Manager. 使用工具->扩展管理器下载并安装NuGet软件包管理器。 Restart MS Visual Studio in order for the changes to take effect. 重新启动MS Visual Studio,以使更改生效。 Go to Package Manager Console install the latest version of Selenium WebDriver by running the command Install-Package Selenium.WebDriver -Version 2.20.0 Install the latest version of Selenium WebDriver Support Classes by running the command Install-Package Selenium.Support 转到程序包管理器控制台,通过运行命令Install-Package Selenium.WebDriver -Version 2.20.0安装最新版本的Selenium WebDriver。通过运行命令Install-Package Selenium.Support安装最新版本的Selenium WebDriver支持类。

Use this as using : 使用此方法:

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;

More details here: Test Automation using C#, Selenium WebDriver and NUnit 此处有更多详细信息: 使用C#,Selenium WebDriver和NUnit进行测试自动化

Put your cursor in the Type and type Ctrl+. 将光标放在“类型”中,然后按Ctrl +。 A resolve context menu will appear and you can select a method for resolving that Type (either by adding a using statement or dotting out the entire path) 将显示一个“解析上下文”菜单,您可以选择一种用于解析该Type的方法(通过添加using语句或添加整个路径)

Tools like Resharper will also help you with this by showing a resolve hint or letting you simply type Ctrl+Enter to resolve while you type (it can also add missing references too). 诸如Resharper之类的工具还可以通过显示解析提示或让您在键入时键入Ctrl + Enter来解析来解决此问题(它也可以添加缺少的引用)。

在此处输入图片说明

In this screenshot the hint above DateTime is what Resharper does when a Type doesn't resolve. 在此屏幕快照中,DateTime上方的提示是Type无法解析时Resharper所做的事情。 Pressing Ctrl+. 按Ctrl +。 will give you the context menu you see below DateTime which is Visual Studio's built in resolve menu. 将为您提供在DateTime下面看到的上下文菜单,它是Visual Studio的内置解析菜单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM