谁能解释一下这个“魔法”?
public interface IWebDriver : ISearchContext, IDisposable
{
string CurrentWindowHandle { get; }
string PageSource { get; }
string Title { get; }
string Url { get; set; }
ReadOnlyCollection<string> WindowHandles { get; }
void Close();
IOptions Manage();
INavigation Navigate();
void Quit();
ITargetLocator SwitchTo();
}
public interface ISearchContext
{
IWebElement FindElement(By by);
ReadOnlyCollection<IWebElement> FindElements(By by);
}
public interface IJavaScriptExecutor
{
object ExecuteAsyncScript(string script, params object[] args);
object ExecuteScript(string script, params object[] args);
}
怎么会
(this.Driver as IJavaScriptExecutor).ExecuteScript("console.log('wtf?')");
工作正常吗?
最佳答案
这是因为main implementation IWebDriver
implements IJavaScriptExecutor
从而提供实现 of those methods .
您尚未提供显示如何实例化驱动程序的代码,但它们都继承自 RemoteWebDriver
:示例是 ChromeDriver
关于c# - 我为什么可以将 IWebDriver 转换为 IJavaScriptExecutor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23112045/