2014-09-03 47 views
0

嗨使用SendKeys函數後,我的網絡驅動程序出現問題。使用SendKeys函數後C#Selenium Web驅動程序異常

我想要做的是在點擊網頁上的「保存」按鈕後點擊對話框上的確定按鈕後,然後嘗試獲取新打開的頁面的網址。

我的網絡驅動程序使用SendKeys函數之前正常工作,因爲我能夠點擊按鈕,得到的URL等

我想這個問題可能是與網頁做失去焦點點擊後在對話中的OK按鈕,所以我用下面的代碼(但是這也不能工作): -

> System.Collections.ObjectModel.ReadOnlyCollection<string> winHandle2 = 
> _webDriver.WindowHandles; 
> 
> _webDriver.SwitchTo().Window(winHandle[0]).SwitchTo(); 

例外我越來越可以看到下面: -

類型的異常「 System.Invalid OperationException'發生在WebDriver.dll中,但未在用戶代碼中處理 附加信息:[JavaScript錯誤:「a is null」{file:「file:/// C:/Users/andrew.short/AppData/Local/Temp /anonymous.3779fc41a91f475c89d01937ed7bb71b.webdriver-profile/extensions/[email protected]/components/command_processor.js「line:8166}]'[JavaScript Error:」a is null「{file:」file:/// C:/ Users \ andrew.short/AppData/Local/Temp/anonymous.3779fc41a91f475c89d01937ed7bb71b.webdriver-profile/extensions/[email protected]/components/command_processor.js「line:8166}]'when calling method:[nsICommandProcessor :: execute] 如果有這種異常的處理程序,程序可能會安全地繼續。

我感謝所有幫助任何人都可以給我:-)

+0

什麼樣的對話框?截圖。在這裏發佈它的HTML。它使用了哪些插件? jQuery的?還有別的嗎? – Arran 2014-09-04 07:14:28

回答

0
public static void SendKeys(this IWebElement element, string value, bool clearFirst) 
{ 
    if (clearFirst) element.Clear(); 
    element.SendKeys(value); 
} 

這個功能很簡單,它的作用是讓我們的代碼簡潔一點。在原來的Selenium RC中,SendKeys將清除文本字段,然後發送所需的文本。在Selenium 2中,除非明確執行,否則不會先清除文本字段。然後,我們可以將它結合起來以允許類似:

myElement.SendKeys("populate field", clearFirst: true); 
相關問題