Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用SendKeys函数后出现C#Selenium Web驱动程序异常_C#_Selenium_Web_Driver - Fatal编程技术网

使用SendKeys函数后出现C#Selenium Web驱动程序异常

使用SendKeys函数后出现C#Selenium Web驱动程序异常,c#,selenium,web,driver,C#,Selenium,Web,Driver,您好,在使用SendKeys功能后,我的web驱动程序出现问题 我试图做的是在点击对话框上的OK按钮之后,在点击网页上的Save按钮之后,我试图获取新打开的网页的url 在使用SendKeys功能之前,我的web驱动程序运行正常,因为我可以单击按钮、获取URL等 我认为问题可能与单击对话框上的OK按钮后网页失去焦点有关,因此我使用了以下代码(但这也不起作用):- >System.Collections.ObjectModel.ReadOnlyCollection winHandle2= >_we

您好,在使用SendKeys功能后,我的web驱动程序出现问题

我试图做的是在点击对话框上的OK按钮之后,在点击网页上的Save按钮之后,我试图获取新打开的网页的url

在使用SendKeys功能之前,我的web驱动程序运行正常,因为我可以单击按钮、获取URL等

我认为问题可能与单击对话框上的OK按钮后网页失去焦点有关,因此我使用了以下代码(但这也不起作用):-

>System.Collections.ObjectModel.ReadOnlyCollection 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-简介/扩展/fxdriver@googlecode.com/components/command_processor.js“line:8166}]”[JavaScript错误:“a为空”{文件:"file:///C:/Users/andrew.short/AppData/Local/Temp/anonymous.3779fc41a91f475c89d01937ed7bb71b.webdriver-简介/扩展/fxdriver@googlecode.com/调用方法[nsicomandprocessor::execute]时的components/command_processor.js“line:8166}]” 如果存在此异常的处理程序,则可以安全地继续该程序。

我感谢任何人能给我的帮助:-)

此函数非常简单,它所做的只是使我们的代码变得简洁。在最初的Selenium RC中,SendKeys会清除一个文本字段,然后发送所需的文本。在Selenium 2中,除非显式执行,否则不会先清除文本字段。然后我们可以将其组合起来,以允许类似以下内容:

myElement.SendKeys("populate field", clearFirst: true);

什么样的对话框?截图。在这里发布HTML。使用什么插件?jQuery?其他什么?
public static void SendKeys(this IWebElement element, string value, bool clearFirst)
{
    if (clearFirst) element.Clear();
    element.SendKeys(value);
}
myElement.SendKeys("populate field", clearFirst: true);