Java 向下滚动以查找文本在android emulator中不起作用的元素
我正在使用Appium桌面服务器(V1.15)以及java客户端as 7.3.0和selenium服务器3.141.59 在我的android emulator中,我需要向下滚动查看文本,并在找到文本后停止滚动。 我尝试使用以下方法:Java 向下滚动以查找文本在android emulator中不起作用的元素,java,selenium,android-emulator,appium,Java,Selenium,Android Emulator,Appium,我正在使用Appium桌面服务器(V1.15)以及java客户端as 7.3.0和selenium服务器3.141.59 在我的android emulator中,我需要向下滚动查看文本,并在找到文本后停止滚动。 我尝试使用以下方法: driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\""+text+"\"));"); driver.findElemen
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\""+text+"\"));");
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textMatches(\"" + containedText + "\").instance(0))"));
where driver is AndroidDriver<MobileElement>
driver.findElementByAndroidUIAutomator(“新的UiScrollable(新的UiSelector()).scrollIntoView(text(\“”+text+“\”));”;
driver.findElement(MobileBy.AndroidUIAutomator(“新UiScrollable(新UiSelector().scrollable(true).instance(0)).ScrollingToView(新UiSelector().textMatches(\”“+containedText+“\”)。instance(0))));
driver是AndroidDriver吗
我面临的问题是,即使找到了正确的文本,滚动也不会停止
请帮忙 这是我使用的自定义滚动方法:
public void scroll(MobileElement anchorElement, double startPointOffsetPercentage, double endpointOffsetPercentage) {
//Determines the type of driver used for the gesture (i.e. AndroidDriver, iOSDriver, etc)
TouchAction scroll = new TouchAction((MobileDriver) anchorElement.getWrappedDriver());
//Gets your anchor element size to use as reference for the scroll
Dimension size = anchorElement.getSize();
int anchor = anchorElement.getCenter().getX();
int startPoint = (int) (size.height * startPointOffsetPercentage);
int endPoint = (int) (size.height * endpointOffsetPercentage);
//Performs the gesture using your anchor element as reference for the action,the start and end offsets as the amount to scroll. Duration can be set to smaller to flick instead of scroll.
scroll.press(PointOption.point(anchor, startPoint)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).moveTo(PointOption.point(anchor, endPoint)).release().perform();
}
我将其用作“滚动到元素”自定义方法:
public void scrollToElement(String elementId, MobileElement scrollableElement) {
MobileDriver driver = (MobileDriver) scrollableElement.getWrappedDriver();
try {
for (int i = 0; i <= 100; i++) {
if (driver.findElements(By.id(elementId)).isEmpty() || !driver.findElement(By.id(elementId)).isDisplayed()) {
scroll(scrollableElement, 0.5, 0.1);
}
}
} catch (NoSuchElementException ignored) {
}
}
public void scrollToElement(String elementId,MobileElement ScrollTableElement){
MobileDriver=(MobileDriver)scrollableElement.getWrappedDriver();
试一试{
对于(int i=0;i请使用资源id而不是可滚动(true)尝试以下操作,因为并非所有情况下,资源id都应该是要滚动到的父元素的id:
driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId(\"com.androidsample.generalstore:id/rvProductList\")).scrollIntoView(text(\""+ item + "\"));"));