我已订阅了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");
}
答案 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);