我的selenium代码在使用selenium最新jar(2.47.1)的firefox和chrome浏览器上成功执行,但我在过去几天在控制台上收到此异常 java.net.SocketException 。 请帮助我,并提前感谢。
我的代码如下所示,它运行正常:
public class testngClass1 {
public static WebDriver driver;
@Test
public static void a() {
driver=new FirefoxDriver();
driver.get("http://www.newtours.demoaut.com/");
driver.manage().window().maximize();
System.out.println("QWERYT");
}
@Test
public static void b() {
driver.findElement(By.name("userName")).sendKeys("QWERYT");
System.out.println("QWERYT");
// driver.quit();
}
}
异常的堆栈跟踪是:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1785)
at java.io.ObjectOutputStream.<init>(ObjectOutputStream.java:247)
at org.testng.remote.strprotocol.SerializedMessageSender.sendMessage(SerializedMessageSender.java:20)
at org.testng.remote.strprotocol.MessageHub.sendMessage(MessageHub.java:44)
at org.testng.remote.strprotocol.RemoteTestListener.onTestSuccess(RemoteTestListener.java:88)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1800)
at org.testng.internal.Invoker.runTestListeners(Invoker.java:1780)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:749)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:846)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1125)
at org.testng.TestRunner.privateRun(TestRunner.java:749)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
at org.testng.SuiteRunner.run(SuiteRunner.java:223)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:965)
at org.testng.TestNG.runSuitesLocally(TestNG.java:890)
at org.testng.TestNG.run(TestNG.java:824)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)
答案 0 :(得分:0)
我也有同样的问题。我试过
-Djava.net.preferIPv4Stack=true
&amp;它对我有用。使用该命令运行
右键点击脚本&gt;点击运行方式&gt;运行配置&gt;参数&gt; VM参数
添加-Djava.net.preferIPv4Stack=true
&gt;
申请&gt;运行