Appium无法操作元素

问题描述 投票:0回答:3

我使用下面的代码来使用 Appium 测试 Android 应用程序,但是当我尝试操作该元素时

driver.findElementById("com.TdMobile.ipems_app:id/login_ipaddress_edit").sendKeys("http://192.168.0.71:8080/ipems/");   

我得到了

java.lang.NullPointerException
,当我调试到该行时,我发现该元素不为空,有人知道发生了这种情况吗?

AndroidDriver driver = null;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("automationName", "Appium");//appium做自动化
cap.setCapability("app", "C:\\Users\\baiming.zhang\\Desktop\\IPEMS-APP.apk");
cap.setCapability("deviceName", "xiaomi-mi_5");//设备名称
cap.setCapability("platformName", "Android"); //安卓自动化还是IOS自动化
cap.setCapability("platformVersion", "6.0"); //安卓操作系统版本
cap.setCapability("udid", "794b155c"); //设备的udid (adb devices 查看到的) 
cap.setCapability("unicodeKeyboard", "True"); //支持中文输入
cap.setCapability("resetKeyboard", "True"); //支持中文输入,必须两条都配置
cap.setCapability("noSign", "True"); //不重新签名apk
driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"),cap);//把以上配置传到appium服务端并连接手机
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//隐式等待

driver.findElementById("com.TdMobile.ipems_app:id/login_ipaddress_edit").sendKeys("http://192.168.0.71:8080/ipems/");//this line failed.
driver.findElementById("com.TdMobile.ipems_app:id/login_user_edit").sendKeys("http://192.168.0.71:8080/ipems/");
driver.findElementById("com.TdMobile.ipems_app:id/login_passwd_edit").sendKeys("http://192.168.0.71:8080/ipems/");
driver.findElementById("com.TdMobile.ipems_app:id/login_login_btn").click();

完整的堆栈跟踪是:

线程“main”中的异常 java.lang.NullPointerException org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:275) 在 org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:316) 在 simple.CalculatorTest.main(CalculatorTest.java:47)

selenium appium
3个回答
1
投票

我将 AndroidDriver 更改为 RemoteWebDriver,它对我来说效果很好


0
投票

最近的 Selenium 更新到版本 3.5.1 似乎破坏了 Appium 的 java 客户端。

更多信息这里

虽然这个帖子指的是Appium的java客户端5.0.0-BETA9,但我知道至少4.1.x版本也被破坏了,因为它发生在我身上。

因此,当前的解决方法是强制 selenium 的版本为 3.4.0,如下所示:

compile ('org.seleniumhq.selenium:selenium-api:3.4.0'){force = true}
compile ('org.seleniumhq.selenium:selenium-remote-driver:3.4.0'){force = true}
compile ('org.seleniumhq.selenium:selenium-support:3.4.0'){force = true}

它对我有用。


0
投票

解决签名难的问题,建议使用google PWA技术,Google PWA官方资料:https://roibest.com

© www.soinside.com 2019 - 2024. All rights reserved.