我需要滚动查找屏幕外的元素。我想出的是:
- 在当前/可见屏幕上搜索所需的元素。
- 如果找不到该元素(即不在屏幕上)-
scrollDown
(在我的情况下,只需要向下滚动)并再次转到步骤1。我已经将测试限制为4次迭代,因为就我而言,这已经足够了,因此请在此处使用您自己的条件。
private void scrollDown() { //if pressX was zero it didn't work for me int pressX = driver.manage().window().getSize().width / 2; // 4/5 of the screen as the bottom finger-press point int bottomY = driver.manage().window().getSize().height * 4/5; // just non zero point, as it didn't scroll to zero normally int topY = driver.manage().window().getSize().height / 8; //scroll with TouchAction by itself scroll(pressX, bottomY, pressX, topY); } private void scroll(int fromX, int fromY, int toX, int toY) { TouchAction touchAction = new TouchAction(driver); touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform(); }
PS您可以从元素获取坐标并在中使用它
scroll。
PSS我用过鸦片1.6.5
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)