我是Apium和java的初学者,我正在寻找driver.scrollTo(" Views")的解决方案,我尝试了下面的代码,而运行时遇到了以下错误:
无法创建新会话。 (原始错误:用于启动应用程序的活动不存在或无法启动!确保它存在并且是可启动的活动)(警告:服务器未提供任何堆栈跟踪信息)
package Android;
import static org.junit.Assert.assertNotNull;
import io.appium.java_client.android.AndroidDriver;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ScrollingToText {
AndroidDriver driver;
@BeforeTest
public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "0123456789ABCDEF");
capabilities.setCapability("browserName", "Android");
capabilities.setCapability("platformVersion", "5.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "com.hmh.api");
capabilities.setCapability("appActivity","com.hmh.ApiDemos");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
}
@Test
public void findScrollable() throws InterruptedException {
//Scroll till element which contains "Views" text If It Is not visible on screen.
// driver.scrollTo("Views");
driver.findElementByAccessibilityId("Views").click();
WebElement radioGroup = driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"+ ".resourceId(\"android:id/list\")).scrollIntoView("
+ "new UiSelector().text(\"Radio Group\"));");
assertNotNull(radioGroup.getLocation());
// Click on Views/.
driver.findElement(By.name("Views")).click();
System.out.println("Scrolling has been started to find text -> Tabs.");
// Scroll till element which contains Tabs text.
// driver.scrollTo("Tabs");
driver.findElementByAccessibilityId("Tabs").click();
System.out.println("Tabs text has been found and now clicking on It.");
// Click on Tabs.
driver.findElement(By.name("Tabs")).click();
}
@AfterTest
public void End() {
driver.quit();
}
}
答案 0 :(得分:0)
(Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity)
如果您的设备上没有安装应用程序,则会出现上述错误。
请先安装它,然后运行它应运行的测试脚本。
希望这些可以帮助你。