2017-08-18 55 views
0

我用下面的代碼來測試Android應用程序與Appium的元素,但是當我嘗試的元素Appium無法操作

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

java.lang.NullPointerException,當我調試到運行線,我發現元素不爲null,有誰知道這發生了?

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(); 

完整堆棧跟蹤是:

異常在線程 「主」 顯示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)

回答

1

我將AndroidDriver改爲RemoteWebDriver,比它對我工作正常

0

最近Selenium更新至版本3.5.1似乎破壞了Appium的Java客戶端。

更多信息here

雖然這個線程引用了Appium的java客戶端5.0.0-BETA9,但我知道至少4.1.x版本也被破壞了,因爲它發生在我身上。

那麼,目前的解決辦法是迫使硒的版本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} 

它爲我工作。