2017-01-25 50 views
1

綜上所述,我想要做的是「開放」的網頁driver.Navigate().GoToUrl("http://somepage.com")然後立即塊從"http://somepage.com/something.asmx/GetStuff"的響應,這樣我可以證實,一些元素有一定的在加載響應之前的類:driver.FindElement(By.CssSelector("buttom.some-button")).GetAttribute("class").Contains("disabled"),然後是disabled如何「塊」的Ajax響應使用Selenium

是這樣的可能,如果是這樣,我怎麼做呢?

我的問題是在什麼它試圖實現類似Selenium Webdriver c# without waiting for page to load

+0

我不認爲你可以使用Selenium爲,但FiddlerCore配對應該是可行的 - http://stackoverflow.com/questions/25541499/how-to-capture-http-request-using-fiddlercore-在-C/26323323#26323323 –

回答

0

投下你IWebDriver(FirefoxDriver,ChromeDriver等),以IJavacriptExecutor的實例,並更換了jQuery $.ajax()方法有存根,如:

var driver = Driver as IJavaScriptExecutor 

driver.ExecuteScript("window.originalAjax = $.ajax") 
driver.ExecuteScript("$.ajax = function() {}") 

// navigate to page, check class 

driver.ExecuteScript("$.ajax = window.originalAjax") 

所以,當您的請求調用進入$.ajax會打一個空白方法。

這樣做的缺點是,你不能輕易得到請求「繼續」封鎖之後,因爲沒有請求曾經創造。您將不得不刷新頁面,而不執行上述步驟,這可能會導致某種誤報。