selenium 操作friefox无法打开网页

selenium3.13.0+geckodriver v0.21.0+firefox61.0.1webdriver可以打开和关闭浏览器,但是不能访问页面,报错如图,想知道原因要如何解决?
打开网页的报错是:
File "C:\Users\sun.yuanbo\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 986, in send
self.sock.sendall(data)
ConnectionAbortedError: [WinError 10053] 您的主机中的软件中止了一个已建立的连接。

先把maven依赖加上
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>12345

思路代码:
WebDriver driver = FirefoxUtils.getFirefoxDriver();
driver.get("网址");
driver.close();//关闭驱动123

FirefoxUtils类:
public class FirefoxUtils {
public static FirefoxDriver getFirefoxDriver(String path) {
File pathToBinary = new File(path);
FirefoxBinary firefoxBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile firefoxProfile = new FirefoxProfile();
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe");//firefox需要geckodriver驱动,这个,百度找咯
return new FirefoxDriver(firefoxBinary, firefoxProfile);
} /**
* 设置默认Firefox路径,返回FirefoxDriver
*
* @return FirefoxDriver
*/
public static FirefoxDriver getFirefoxDriver() { return FirefoxUtils.getFirefoxDriver("D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");//这里就是自己装的火狐路径呢
}
}123456789101112131415161718

selenium的话,我是用来操作网页进行自动化相关操作的,selenium的文档的话,我会上传到CSDN资源里面。
温馨提示:答案为网友推荐,仅供参考
相似回答