gpt4 book ai didi

java - 寻找 driver.scrollTo ("Views"的解决方案)

转载 作者:行者123 更新时间:2023-11-28 20:52:05 27 4
gpt4 key购买 nike

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

无法创建新 session 。 (原始错误:用于启动应用程序的 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();
}
}

最佳答案

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

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

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

希望这些对你有帮助。

关于java - 寻找 driver.scrollTo ("Views"的解决方案),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42644848/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com