我是appium测试工具的初学者,我尝试滚动到文本程序,但它得到以下错误“方法scrollTo(String)未定义类型AndroidDriver”,
从那里我学会'scrollTo'方法被折旧..有没有任何解决方案我尝试下面的代码
package Android;
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.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", "io.appium.android.apis");
capabilities.setCapability("appActivity","io.appium.android.apis.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 ScrollToText() throws InterruptedException {
//Scroll till element which contains "Views" text If It Is not visible on screen.
driver.scrollTo("Views");
// 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");
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)
您应该可以使用
查找并滚动到MobileElement
MobileElement radioGroup = driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()"
+ ".resourceId(\"android:id/list\")).scrollIntoView("
+ "new UiSelector().text(\"Radio Group\"));");
同样要滚动到列表中的子元素,您可以使用 -
MobileElement radioGroup = list
.findElement(MobileBy
.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView("
+ "new UiSelector().text(\"Radio Group\"));"));
您可以使用所需元素的值替换anroid:id/list
和文本Radio Group
。
来源 - findScrollabe()
和scrollingToSubElement()
编辑 - 对于寻求iOS帮助的任何人,IOSScrollingSearchingTest
都应该有所帮助。
答案 1 :(得分:0)
使用以下代码将对我有用。
private String str = "Select";
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+str+"\").instance(0))");