2014-09-03 117 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); 
相关问题