问题描述:
当使用appium 的java-client依赖去调用sendKey方法向控件发送文本时候,appium服务器报错如下:
unknown error: an X display is required for keycode conversions, consider using Xvfb
在window的开发环境中,调整chromeDriver的版本,手机使用系统自带的输入键盘,查找到对应控件后,能正常sendKey。
但在linux环境下却不行,排除了chromeDriver的版本和appium版本问题后,结合网上资料,网上并没有具体的解决办法。
再git上找到一个类似的解决描述:
Ensure seleniumAddress: 'http://localhost:4444/wd/hub' matches your selenium server and avoid setting chromeOnly since that will effectively avoid using the headless selenium server.
Also, Xvfb needs to run before webdriver-manager and you're missing xvfb-run given you seem to need it to do the X authority dance for you:
#!/bin/sh
export DISPLAY=:1
Xvfb $DISPLAY -ac -screen 0 1280x1024x8 &
sleep 1
xvfb-run webdriver-manager start &
最后具体了解linux 下的xvfb的原理,测试尝试解决成功解决sendKey报错问题。
首先linux下需要安装Xvfb ,对应的centos系统安装yum -y install Xvfb
安装成功后,启动Xvfb:
Xvfb :1 -ac -screen 0 1280x1024x8 &
然后通过xvfb启动appium服务
xvfb-run appium -p4725 &
或者到appium源码目录下node .执行
xvfb-run node . -p4725 &