谁能解释这个“魔术”?

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?')");


正常吗?

最佳答案

这是因为IWebDriver main implementation IJavaScriptExecutorimplements并因此提供了实现of those methods

您尚未提供显示如何实例化驱动程序的代码,但它们均继承自RemoteWebDriver:例如,ChromeDriver

关于c# - 如何将IWebDriver转换到IJavaScriptExecutor?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23112045/

10-11 17:05