2014-10-03 86 views
1

我訂閱了WebDriver的Navigated和Navigating事件,但事件未被觸發。如果他們不工作,他們有什麼用?爲了讓他們觸發,我還需要做些額外的事情嗎?導航/導航事件在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"); 
} 

回答

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);