In order to execute JavaScript in a IWebDriver
instance you need to cast the IWebDriver
to a new interface, IJavaScriptExecutor
IWebDriver driver;
IJavaScriptExecutor jsDriver = driver as IJavaScriptExecutor;
You can now access all the methods available on the IJavaScriptExecutor
instance which allow you to execute Javascript, for example:
jsDriver.ExecuteScript("alert('running javascript');");