我想在我的android設備上打開一個移動.apk文件,然後選擇一個國家「USA」並點擊「保存」按鈕。Android應用程序自動化腳本:通過Appium,Selenium WebDriver,Java:NoSuchElementFoundException
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import io.appium.java_client.android.AndroidDriver;
public class DemoC {
AndroidDriver driver =null;
DesiredCapabilities capabilities;
File app = new File("C:\\Users\\310250972\\workspace\\DreamMapper_2.5_Alpha_July_5_65.apk");
@Test(priority=1)
public void invokeApp() throws MalformedURLException
{
capabilities = new DesiredCapabilities();
capabilities.setCapability("automationName","Appium");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("platformVersion","6.0.1");
capabilities.setCapability("deviceName","Galaxy S6");
capabilities.setCapability("app", app.getAbsolutePath());
//capabilities.setCapability("appPackage","com.philips.sleepmapper.root");
//capabilities.setCapability("appactivity","com.philips.sleepmapper.activity.SplashScreenActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test(priority=2)
public void selectCountry() throws InterruptedException{
Thread.sleep(20000);
//driver.findElement(By.xpath("//android.widget.TextView[Contain]"))
driver.findElement(By.xpath("//android.widget.TextView[contains(@text='United States')]")).click();
Thread.sleep(10000);
driver.findElement(By.xpath("//android.widget.TextView[contains(@text='Save')]")).click();
// driver.findElement(By.name("Save")).click();
}
}[I want to select "United States" and click on "Save" button][1]
//執行時,測試方法「selectCountry()」失敗。 Nosuchelementfoundexception