导航/导航事件在PhantomJS WebDriver中不起作用

时间:2014-10-03 13:46:05

标签: c# selenium-webdriver phantomjs

我已订阅了WebDriver的导航和导航事件,但未触发事件。如果它们不起作用,它们的用途是什么?为了让它们被触发,我还需要做些什么吗?

_driver = new PhantomJSDriver();
EventFiringWebDriver eventDriver = new EventFiringWebDriver(_driver);
eventDriver.Navigating += navigatedHandler;
_driver.Navigate().GoToUrl(yt);

private void navigatedHandler(object sender, WebDriverNavigationEventArgs args)
{
    MessageBox.Show("navigating");
}

1 个答案:

答案 0 :(得分:2)

您通过使用初始IWebDriver对象进行导航来规避事件机制。调用EventFiringWebDriver实例上的方法将正确触发事件。对于您的示例代码:

_driver = new PhantomJSDriver();
EventFiringWebDriver eventDriver = new EventFiringWebDriver(_driver);
eventDriver.Navigating += navigatingHandler;

// This line changes. Use eventDriver instead of _driver to navigate. 
eventDriver.Navigate().GoToUrl(yt);