简体   繁体   中英

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. However, I cannot find out which "using" directive to put at the top of the file for it to work. 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. 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. Restart MS Visual Studio in order for the changes to take effect. 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

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

Put your cursor in the Type and type 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)

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).

在此处输入图片说明

In this screenshot the hint above DateTime is what Resharper does when a Type doesn't resolve. Pressing Ctrl+. will give you the context menu you see below DateTime which is Visual Studio's built in resolve menu.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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