'OpenQA.Selenium.IWebDriver'不包含'ExecuteScript'的定义,也没有扩展方法'ExecuteScript'

时间:2016-07-26 11:26:22

标签: c# selenium

enter image description here运行代码时在(ExecuteScript)中出错,请解决它

for (int second = 0; ; second++)
{
     if (second >= 60)
     {
        break;
     }
     river.ExecuteScript("window.scrollBy(0,150)", "");
     Thread.Sleep(1000);
}

1 个答案:

答案 0 :(得分:0)

假设您要执行Javascript执行和您的" river"类型是WebDriver

使用此代码:

IJavaScriptExecutor jsExecutor = (IJavaScriptExecutor)river;

                for (int second = 0; ; second++)
                {
                     if (second >= 60)
                     {
                        break;
                     }
                    jsExecutor.ExecuteScript("window.scrollBy(0,150)", new object[] { element });

                    Thread.sleep(1000);
                }

此处元素 - > IwebElement

希望这有帮助