Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.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
C# Selenium WebDriver with C:从下拉菜单中选择项(在IE中不起作用)_C#_Selenium - Fatal编程技术网

C# Selenium WebDriver with C:从下拉菜单中选择项(在IE中不起作用)

C# Selenium WebDriver with C:从下拉菜单中选择项(在IE中不起作用),c#,selenium,C#,Selenium,需要从下拉菜单中选择默认隐藏的第二项。问题在于,它在FireFox 41浏览器中工作正常,但在Internet Explorer 11中工作不正常。我在VisualStudio2010中将SeleniumWeb驱动程序与C、nUnit一起使用。使用Selenium服务器和IEDriver在远程VM上执行测试 HTML看起来像: <ul id="CVC" class="buttonMenu" style="visibility: hidden; left: 183px;"> <

需要从下拉菜单中选择默认隐藏的第二项。问题在于,它在FireFox 41浏览器中工作正常,但在Internet Explorer 11中工作不正常。我在VisualStudio2010中将SeleniumWeb驱动程序与C、nUnit一起使用。使用Selenium服务器和IEDriver在远程VM上执行测试

HTML看起来像:

<ul id="CVC" class="buttonMenu" style="visibility: hidden; left: 183px;">
  <li class="menuItem">First</li>
  <li class="menuItem">Second</li>
  <li class="menuItem">Third</li>
</ul>
在Internet Explorer中运行测试时,出现一个错误:

Test Name:  Bookmark
Test FullName:  EEE.Tests.BT.BB
Test Source:    d:\Selenium\Automation\EEEAutomation\EEEAutomation\Tests\BT.cs : line 19
Test Outcome:   Failed
Test Duration:  0:00:39.319

Result Message: OpenQA.Selenium.ElementNotVisibleException : Cannot click on element (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 35 milliseconds
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'wkqacl0801', ip: '10.101.6.104', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
Capabilities [{browserAttachTimeout=0, enablePersistentHover=true, ie.forceCreateProcessApi=false, pageLoadStrategy=normal, ie.usePerProcessProxy=false, ignoreZoomSetting=false, handlesAlerts=true, version=11, platform=WINDOWS, nativeEvents=true, ie.ensureCleanSession=false, elementScrollBehavior=0, ie.browserCommandLineSwitches=, requireWindowFocus=false, browserName=internet explorer, initialBrowserUrl=http://localhost:39901/, takesScreenshot=true, javascriptEnabled=true, ignoreProtectedModeSettings=false, enableElementCacheCleanup=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=dismiss}]
Session ID: 6f09c88a-bd73-4cab-9312-0587c8345023
Result StackTrace:  
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at EEE.Tests.SubTests.CreateBBSubTest.Execute(IWebDriver wd) in d:\Selenium\Automation\EEEAutomation\EEEAutomation\Tests\SubTests\CreateBBSubTest.cs:line 103
at EEE.Tests.BT.BB() in d:\Selenium\Automation\EEEAutomation\EEEAutomation\Tests\BT.cs:line 54

有人知道如何在Internet Explorer 11中使用它吗?

不确定IE是否应该被视为真正的浏览器。在任何情况下,我重读你的问题,似乎你希望IE的工作就像一个点击事件的浏览器。在这种情况下,您可能希望帮助它:

using (var wd = new InternetExplorerDriver(
  new InternetExplorerOptions {EnableNativeEvents = false}))
{
  //your code
}

不确定IE是否应该被视为真正的浏览器。在任何情况下,我重读你的问题,似乎你希望IE的工作就像一个点击事件的浏览器。在这种情况下,您可能希望帮助它:

using (var wd = new InternetExplorerDriver(
  new InternetExplorerOptions {EnableNativeEvents = false}))
{
  //your code
}

我通过使用JavaScript找到了解决方案。我不确定这是否是最好的解决方案,但至少它不仅适用于FF,也适用于IE浏览器:

((IJavaScriptExecutor)wd).ExecuteScript("$('#CVC li:eq(1)').click()");
wd.FindElement(By.Id("TITLE")).Clear();
wd.FindElement(By.Id("TITLE")).SendKeys("blabla");
wd.FindElement(By.Id("CVC_OK")).Click();

我通过使用JavaScript找到了解决方案。我不确定这是否是最好的解决方案,但至少它不仅适用于FF,也适用于IE浏览器:

((IJavaScriptExecutor)wd).ExecuteScript("$('#CVC li:eq(1)').click()");
wd.FindElement(By.Id("TITLE")).Clear();
wd.FindElement(By.Id("TITLE")).SendKeys("blabla");
wd.FindElement(By.Id("CVC_OK")).Click();
这对我很有用:

_driver.FindElement(By.Id("IdOfControl")).SendKeys(value);
这对我很有用:

_driver.FindElement(By.Id("IdOfControl")).SendKeys(value);

早些时候,当我尝试使用SelectElement时,我看到了一个错误:OpenQA.Selenium.Support.UI.UnexpectedTagNameException:Element本应为select,但为ul,看起来无法使用,当我使用var result时,VS显示错误:无法将void赋值给隐式类型的局部变量,因此我在没有该变量的情况下使用了:wd.FindElementBy.IdCVC.FindElementBy.cssselector选项[value='1']。单击;但收到错误:OpenQA.Selenium.NoSuchElementException:无法按预期找到css选择器==选项[value=1]为wd.FindElementBy.IdCVC.FindElementsBy.TagNameli[1]的元素。选择;在Firefox浏览器中运行良好。切换到IE时收到错误:OpenQA.Selenium.ElementNonVisibleException:无法单击元素。抱歉,响应太晚。当我使用nativeevents=false时,错误仍然存在。例如:var desiredCapabilities=desiredCapabilities.InternetExplorer;DesiredCapabilityNativeEvents,false;返回新的RemoteWebDriverNewUriettings.Default.RemoteUrl,desiredCapabilities;但毕竟我找到了一个解决方案。早些时候,当我尝试使用SelectElement时,我看到一个错误:OpenQA.Selenium.Support.UI.UnexpectedTagNameException:Element应该是select的,但它是ul的,看起来无法使用,当我使用var result时,VS显示错误:无法将void赋值给隐式类型的局部变量,因此我在没有该变量的情况下使用了:wd.FindElementBy.IdCVC.FindElementBy.cssselector选项[value='1']。单击;但收到错误:OpenQA.Selenium.NoSuchElementException:无法按预期找到css选择器==选项[value=1]为wd.FindElementBy.IdCVC.FindElementsBy.TagNameli[1]的元素。选择;在Firefox浏览器中运行良好。切换到IE时收到错误:OpenQA.Selenium.ElementNonVisibleException:无法单击元素。抱歉,响应太晚。当我使用nativeevents=false时,错误仍然存在。例如:var desiredCapabilities=desiredCapabilities.InternetExplorer;DesiredCapabilityNativeEvents,false;返回新的RemoteWebDriverNewUriettings.Default.RemoteUrl,desiredCapabilities;但毕竟我找到了解决办法。