Appium[iOS原生应用程序]-如何使用Java滚动到特定元素/对象?
我想滚动到一个特定的元素,它目前在屏幕上不可见,但它在页面的某个地方,我必须向下滚动。因此,Appium[iOS原生应用程序]-如何使用Java滚动到特定元素/对象?,java,appium,ios-ui-automation,appium-ios,python-appium,Java,Appium,Ios Ui Automation,Appium Ios,Python Appium,我想滚动到一个特定的元素,它目前在屏幕上不可见,但它在页面的某个地方,我必须向下滚动。因此,dr.scrollTo()不起作用,我尝试了jsExecutor.executeScript(“mobile:scroll”,scrollObject),但也不起作用。有什么想法吗 如果可能的话,我希望它是通用的,这样它可以在对象位置不确定的地方向上和向下搜索。原始appium解决方案: 作为一种解决方法,您可以滚动/滑动,直到iOS显示/启用/可单击元素,或者Android仅存在原始appium解决方案
dr.scrollTo()
不起作用,我尝试了jsExecutor.executeScript(“mobile:scroll”,scrollObject)
,但也不起作用。有什么想法吗
如果可能的话,我希望它是通用的,这样它可以在对象位置不确定的地方向上和向下搜索。原始appium解决方案:
作为一种解决方法,您可以滚动/滑动,直到iOS显示/启用/可单击元素,或者Android仅存在原始appium解决方案:
作为一种解决方法,您可以滚动/滑动,直到iOS显示/启用/可单击元素,或者仅存在于Android中。该解决方案是一种解决方法。这方面没有确切的功能。 首先,让我们收集需求- 滚动页面(范围为-[当前页面位置,页面结尾]),直到给定元素可见 对于滚动,我们可以使用-
driver.swipe(startx, starty, startx, endy, 1000);
为了找到元素可见性,我们可以使用如下代码-
try {
dr.findElement(By.xpath(xpath); // find element with whatever Selector, I am using xpath
if (dr.findElementsByXPath(xpath).size()>0 && dr.findElement(By.xpath(xpath)).isDisplayed()){
System.out.println("Element found by xpath : " + xpath);
return true;
} else
return false;
} catch (NoSuchElementException e1) {
System.out.println("Object not found");
return false;
} catch (Exception e2) {
System.out.println("Unhandled Exception found");
e2.printStackTrace();
throw e2;
}
现在我们必须设置一个条件,如果最后一个元素可见,滚动应该停止。为此,我们可以修改当前元素的xpath,并检查该xpath找到的元素的可见性,如-
String xpath_last = elementxpath.concat("/../*[last()]"); // if we are scrolling downwards then [last()]. But if we are scrolling up then make it [1]
这就完成了你的条件。我想这应该够了 解决方案是一种变通方法。这方面没有确切的功能。 首先,让我们收集需求- 滚动页面(范围为-[当前页面位置,页面结尾]),直到给定元素可见 对于滚动,我们可以使用-
driver.swipe(startx, starty, startx, endy, 1000);
为了找到元素可见性,我们可以使用如下代码-
try {
dr.findElement(By.xpath(xpath); // find element with whatever Selector, I am using xpath
if (dr.findElementsByXPath(xpath).size()>0 && dr.findElement(By.xpath(xpath)).isDisplayed()){
System.out.println("Element found by xpath : " + xpath);
return true;
} else
return false;
} catch (NoSuchElementException e1) {
System.out.println("Object not found");
return false;
} catch (Exception e2) {
System.out.println("Unhandled Exception found");
e2.printStackTrace();
throw e2;
}
现在我们必须设置一个条件,如果最后一个元素可见,滚动应该停止。为此,我们可以修改当前元素的xpath,并检查该xpath找到的元素的可见性,如-
String xpath_last = elementxpath.concat("/../*[last()]"); // if we are scrolling downwards then [last()]. But if we are scrolling up then make it [1]
这就完成了你的条件。我想这应该够了