selenium+phantomjs报错:Unable to find a free port的分析和解决
selenium+phantomjs报错:Unable to find a free port的分析和解决
1 现象
在做项目时,发现在某台机器上使用selenium+phantomjs时报如下错误:
java.lang.RuntimeException: Unable to find a free port
at org.openqa.selenium.net.PortProber.findFreePort(PortProber.java:67)
at org.openqa.selenium.phantomjs.PhantomJSDriverService$Builder.build(PhantomJSDriverService.java:443)
...
2 分析
通过跟踪源代码(org.openqa.selenium.net.PortProber.createAcceptablePort),发现:
if (FIRST_PORT == LAST_PORT) {
return FIRST_PORT;
}
在该服务器上,FIRSTPORT = LASTPORT = 1024,因此总是返回1024。
查看服务器的可用本地端口配置,如下:
[gyx@interface01 ~]$ cat /proc/sys/net/ipv4/ip_local_port_range
1024 65535
因为这台机器的最低可用端口配置成了1024,而其他机器都比这个大很多,因此造成了上述问题。
3 解决办法
因为该服务器还有别的用处,不能随意修改可用端口配置,所以,暂时通过修改createAcceptablePort中相应代码解决问题。如下:
if (FIRST_PORT == LAST_PORT) {
// return FIRST_PORT;
final int randomInt = random.nextInt();
System.out.println("randomInt = " + randomInt);
final int portWithoutOffset = Math.abs(randomInt % (HIGHEST_PORT - START_OF_USER_PORTS + 1));
return portWithoutOffset + FIRST_PORT;
}
selenium+phantomjs报错:Unable to find a free port的分析和解决的更多相关文章
- selenium python 报错“ unable to find binary in default location”
selenium python 报错如下: raise exception_class(message, screen, stacktrace)selenium.common.exceptions.W ...
- python selenium phantomjs 报错
报错: webdriver.PhantomJS() raise exception_class(value)selenium.common.exceptions.WebDriverException: ...
- selenium启动报错“ incorrect JSON status mapping for 'unknown error' (500 expected)”
前面讲了工程启动报错“selenium启动报错Unable to read VR Path Registry from C:\Users\clinva\AppData\Local\openvr\ope ...
- selenium + PhantomJS使用时 PhantomJS报错解决
selenium + PhantomJS使用时 PhantomJS报错解决 在做动态网页爬虫时用到了selenium + PhantomJS,安装好之后运行时报错: UserWarning: Sele ...
- delphi调试需要管理员权限程序报错“Unable to create process:请求的操作需要提升”
delphi调试启动需要UAC权限的程序的时候会报错“Unable to create process:请求的操作需要提升”.这是因为delphi没有以管理员身份启动,这样delphi createp ...
- AS添加依赖报错Unable to merge dex
AS添加依赖报错Unable to merge dex 最近在给项目添加依赖的时候,要给项目导入Bmob的SDK,参照Bmob的官方文档,可以直接在app的build.gradle文件中添加 //Bm ...
- centos6.5环境wget报错Unable to establish SSL connection
centos6.5环境wget报错Unable to establish SSL connection [root@centossz008 src]# wget --no-check-certific ...
- linux 下通过xhost进入图形界面,经常会出现报错“unable to open display”
linux 下通过xhost进入图形界面,经常会出现报错“unable to open display” linux下的操作步骤如下: [root@localhost ~]# vncserver N ...
- git clone 报错Unable to negotiate with xxx.xxx.xxx.xxx port 12345: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1
在执行git clone命令报错 Unable to negotiate with xxx.xxx.xxx.xxx port 12345: no matching key exchange metho ...
随机推荐
- VIewPage+Fragment
效果图: 代码 public class NewOrderListFargmentActivity extends BaseActivity implements OnClickListener { ...
- [多路dp]更难的矩阵取数问题
https://www.51nod.com/tutorial/course.html#!courseId=11&isCurrent=1 解题关键:1.注意i和j的最大取值都是n,k是i与j的和 ...
- hbase exporter importer 导出 导入
导出: bin/hbase org.apache.hadoop.hbase.mapreduce.Export bigtable /user/bigtable_bak/ 导入: bin/hbase or ...
- github的简单操作
之前初学过一点git版本控制工具,利用github做仓库,照着github上的文档练习的了一下.不过那只篇只是照虎画猫(我的水平只能照着老虎画个猫模样,嘻嘻!). 最近在学hibernate,公司与家 ...
- 4.Windows应急响应:勒索病毒
0x00 前言 勒索病毒,是一种新型电脑病毒,主要以邮件.程序木马.网页挂马的形式进行传播.该病毒性质恶劣. 危害极大,一旦感染将给用户带来无法估量的损失.这种病毒利用各种加密算法对文件进行加密,被感 ...
- 7.25实习培训日志-Oracle SQL(一)
Oracle SQL(一) 重点 尽量避免select *,影响性能,不直观. 慎用Distinct,会排序,影响性能,用exists 排序尽量利用索引,索引有序 索引列不要加函数,会使索引失效 外连 ...
- c# 指针unsafe/fixed -- 【一】
指针C#unsafefixed 目录(?)[-] 概述 unsafe fixed 1.1 概述 unsafe关键字表示不安全上下文,该上下文是任何涉及指针的操作所必需的.可以在属性.方法.类的声明中使 ...
- C#类和类的实例
类 ,顾名思义就是分类.类别的意思.我们要面向对象编程,就需要对不同的事物进行分类.类可以说是.net面向对象的核心. 类:就是具有相同的属性和功能的对象的抽象的集合. 1.类的定义 <访问修 ...
- Spring Cloud 简介
SpringCloud 简介 SpringCloud是一个基于SpringBoot实现的微服务架构开发工具.它为微服务架构中涉及的配置管理.服务治理.断路器.智能路由.微代理.控制总线.全局锁.决策竞 ...
- Linux命令使用
命令行创建设置用户密码 $ sudo useradd -m -r username $ cat "username:password" | sudo chpasswd -m 查询u ...