簡體   English   中英

使用SendKeys函數后C#Selenium Web驅動程序異常

[英]C# Selenium Web Driver Exception after using SendKeys Function

嗨,使用SendKeys函數后,我的Web驅動程序出現了問題。

我想做的是在單擊網頁上的“保存”按鈕后,在對話框中單擊“確定”按鈕后,然后嘗試獲取新打開頁面的URL。

使用SendKeys函數之前,我的Web驅動程序可以正常運行,因為我可以單擊按鈕,獲取url等。

我認為問題可能與單擊對話框上的“確定”按鈕后網頁失去焦點有關,所以我使用了以下代碼(但這也不起作用):

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

我得到的異常可以在下面看到:

WebDriver.dll中發生類型'System.InvalidOperationException'的異常,但未在用戶代碼中處理。其他信息:[JavaScript錯誤:“ a為空” {文件:“ file:/// C:/Users/andrew.short /AppData/Local/Temp/anonymous.3779fc41a91f475c89d01937ed7bb71b.webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js“行:8166}]'[JavaScript錯誤:“ a為null” {file:” file: ///C:/Users/andrew.short/AppData/Local/Temp/anonymous.3779fc41a91f475c89d01937ed7bb71b.webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js“行:8166}]'在調用方法時: [nsICommandProcessor :: execute]如果存在用於此異常的處理程序,則可以安全地繼續執行該程序。

我感謝任何人都能給我的幫助:-)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM