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 ...
随机推荐
- HBase 官方文档
HBase 官方文档 Copyright © 2010 Apache Software Foundation, 盛大游戏-数据仓库团队-颜开(译) Revision History Revision ...
- ParentViewController中添加SubViewController(IOS学习)
我是用的是Container.addSubView的方法. 1. ParentViewController.m的@interface()中添加2个子vc的实例变量,代码如下 @property (no ...
- 关于Android进程的启动和消亡
在打开一个应用程序的时候,packagemanager会根据manifest文件去查找有没有相应的进程已启动,若果没有启动,那么就启动一个新的进程 进程退出有两种方式,用finish结束主activi ...
- SSM集成shiro 致使Controller无法自动注册service
由于shiro在web.xml中配置属于过滤器,其中在web.xml中的加载顺序为: <context-param>(上下文) > listener > filter > ...
- Asp.net Core 使用 EntityFrameworkCore 1.1
前言 相比大家也在开发中是非常喜欢用ORM的.今天就来介绍一下EntityFrameworkCore的使用方法. 自从EF Core升级到1.1之后,确实变化挺大的.如果没试过真的不知道坑是挺多的.今 ...
- win7 64位安装nokia 920驱动
折腾了很长时间,终于安装成功,先将一些步骤记下来,此方法适用于哪些网上常规方法无法安装驱动的: 需要注意920不要连到电脑上的USB3.0接口,相关文件下载地址:http://pan.baidu.co ...
- [CentOS7] SELinux
声明:本文主要总结自:鸟哥的Linux私房菜-第十六章.程序管理與 SELinux 初探,如有侵权,请通知博主 SELinux = Security Enhanced Linux 传统的文件权限与账号 ...
- 基础篇 - pg_isready
pg_isready 发起一个到指定 PostgreSQL数据库的连接检查. 使用方法: pg_isready [选项]... 选项: -d, --dbname=DBNAME 数据库名 -q, --q ...
- 存储引擎:MySQL系列之七
一.MyISAM存储引擎 缺点: 不支持事务 最小粒度锁:表级 读写相互阻塞,写入不能读,读时不能写 不支持MVCC(支持多版本并发控制机制) 不支持聚簇索引 不支持数据缓存 不支持外键 崩溃恢复性较 ...
- Oracle插入中文数据乱码 设置服务器编码和客户端编码一致