【问题标题】:Looking for solution to driver.scrollTo("Views")寻找 driver.scrollTo("Views") 的解决方案
【发布时间】:2017-07-27 10:58:53
【问题描述】:

我是 Apium 和 java 的初学者,我正在寻找 driver.scrollTo("Views") 的解决方案,我尝试了以下代码,运行时出现以下错误:

无法创建新会话。 (原始错误:用于启动应用程序的 Activity 不存在或无法启动!确保它存在并且是可启动的 Activity)(警告:服务器未提供任何堆栈跟踪信息)

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

【问题讨论】:

    标签: java testing appium


    【解决方案1】:
     (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity) 
    

    当您的设备上没有安装应用程序时会出现上述错误。

    请先安装它,然后运行它应该运行的测试脚本。

    希望这些对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 2019-01-16
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      相关资源
      最近更新 更多