我正在使用Selinium webdriver,Nunit框架并使用IE浏览器。我有以下代码。 Tt没有执行第二种方法(添加危险)。我正在粘贴代码和堆栈跟踪。有人可以告诉我哪里出了问题。 提前谢谢。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using NUnit.Framework;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
namespace Nunit2
{
[TestFixture]
class SeleniumTest
{
public IWebDriver driver;
[TestFixtureSetUp]
public void SetUp()
{
driver = new InternetExplorerDriver(@"C:\Selenium_App\IE DriverServer_32bit2.48.0");
driver.Navigate().GoToUrl("https://testwebsite");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(6000));
IWebElement loginbutton = driver.FindElement(By.Id("Image2"));
loginbutton.Click();
System.Console.WriteLine("page title is" + driver.Title);
driver.FindElement(By.Id("Loginlogin")).SendKeys("AutomationUser");
driver.FindElement(By.Id("Loginpassword")).SendKeys("safety35");
IWebElement log = driver.FindElement(By.Id("LoginButton_DoLogin"));
log.Click();
}
[TestFixtureTearDown]
public void TearDown()
{
driver.Quit();
driver.Dispose();
}
[Test]
public void AddAction()
{
// driver.Navigate().GoToUrl("https://test.riskmanager.co.nz/");
// driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(6000));
//IWebElement loginbutton = driver.FindElement(By.Id("Image2"));
//loginbutton.Click();
//System.Console.WriteLine("page title is" + driver.Title);
//driver.FindElement(By.Id("Loginlogin")).SendKeys("AutomationUser");
//driver.FindElement(By.Id("Loginpassword")).SendKeys("safety35");
//IWebElement log = driver.FindElement(By.Id("LoginButton_DoLogin"));
//log.Click();
// driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1000));
Actions action = new Actions(driver);
IWebElement actionsMenu = driver.FindElement(By.XPath(".//div[2]/ul/li[2]/a/span[1]"));
action.MoveToElement(actionsMenu).Build().Perform();
driver.FindElement(By.XPath(".//div[2]/ul/li[2]/ul/li[1]/a/span")).Click();
IWebElement actiontitle = driver.FindElement(By.Id("actrpnlActionTitleInputtitle"));
actiontitle.SendKeys("Testaction");
driver.FindElement(By.Id("actrpnlDateDueInputdatedue")).SendKeys("16 Nov 16");
IWebElement element = driver.FindElement(By.Id("actrpnlReportingLineInputpnlLineDropdownlineid"));
SelectElement select = new SelectElement(element);
select.SelectByValue("196E");
IWebElement PersonResponsible = driver.FindElement(By.Id("actrpnlPersonResponsibleInputempText"));
PersonResponsible.SendKeys("a");
IWebElement se = driver.FindElement(By.XPath(".//html/body/ul[2]/li/a"));
se.Click();
IWebElement Addaction = driver.FindElement(By.Id("actrButton_Insert"));
Addaction.Click();
}
[Test]
public void AddHazard()
{
Actions hazard = new Actions(driver);
IWebElement hazardmenu = driver.FindElement(By.XPath(".//div[3]/ul/li[3]/a/span[1]"));
hazard.MoveToElement(hazardmenu).Build().Perform();
driver.FindElement(By.XPath(".//div[3]/ul/li[3]/ul/li[1]/a/span")).Click();
System.Console.WriteLine("second test");
}
}
}
堆栈跟踪
est名称:AddHazard 测试FullName:Nunit2.SeleniumTest.AddHazard 测试源:C:\ Users \ Anuradh Vanguri \ Documents \ Visual Studio 2015 \ Projects \ Nunit2 \ Nunit2 \ Class1.cs:第72行 测试结果:失败 测试时间:0:00:38.151
结果StackTrace:
at c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs中的OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求):第154行
at c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs中的OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(命令commandToExecute):第114行
at c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ DriverServiceCommandExecutor.cs中的OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令commandToExecute):第78行
在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2参数)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:第910行
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism,String value)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:第954行
在OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath)中的c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:line 700
在OpenQA.Selenium.By。<> c__DisplayClasse.b__c(ISearchContext context)中c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ By.cs:第167行
at c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ By.cs中的OpenQA.Selenium.By.FindElement(ISearchContext context):第309行
在OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)中的c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:第330行
在Nunit2.SeleniumTest.AddHazard()在C:\ Users \ Anuradh Vanguri \ Documents \ Visual Studio 2015 \ Projects \ Nunit2 \ Nunit2 \ Class1.cs:第74行
--WebException
在System.Net.HttpWebRequest.GetResponse()
at c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs中的OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求):第141行
--IOException
在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小)
在System.Net.PooledStream.Read(Byte []缓冲区,Int32偏移量,Int32大小)
在System.Net.Connection.SyncRead(HttpWebRequest请求,布尔userRetrievedStream,布尔probeRead)
--SocketException
在System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags)
在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小)
结果消息:
OpenQA.Selenium.WebDriverException:抛出了一个带有空响应的异常,向URL http://localhost:61917/session/a992c864-0c93-45dc-bec8-0d74e68ecceb/element的远程WebDriver服务器发送HTTP请求。异常的状态是ReceiveFailure,消息是:基础连接已关闭:接收时发生意外错误。
----> System.Net.WebException:基础连接已关闭:接收时发生意外错误。
----> System.IO.IOException:无法从传输连接读取数据:远程主机强制关闭现有连接。
----> System.Net.Sockets.SocketException:远程主机强制关闭现有连接
答案 0 :(得分:0)
答案 1 :(得分:0)
尝试在与IE驱动程序的交互之间添加超时。
看看这个主题,讨论了一些IE问题: Selenium error: No response from server for url http://localhost:7055