使用Appium,Seleniumnetworking驱动程序,Node js,Mocha等select不在原生android应用程序的屏幕上的UI元素

我正在testing一个原生的Android应用程序,并需要点击屏幕底部的button。 我已经看到了很多使用Java和Javascript的例子,但我使用Node.js,似乎没有任何工作。 我对这个东西很新,在这么简单的事情上浪费了太多的时间。

例如,点击一个屏幕上的元素,这个工作:

it("Select Button Test",function(){ return driver .setImplicitWaitTimeout(timeoutWait) .elementByXPath('//android.widget.TextView[@text=\'My Button\']').click(); }); 

此外,完整的xpath适用于屏幕上的元素 – 在这种情况下:

  var myButton ='//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.view.View[1]/android.widget.FrameLayout[1]/android.widget.RelativeLayout[1]/android.widget.ScrollView[1]/android.widget.LinearLayout[1]/android.widget.TableLayout[1]/android.widget.TableRow[10]'); it("Select Button Test",function(){ return driver .setImplicitWaitTimeout(timeoutWait) .elementByXPath(myButton).click(); }); 

通过在testing运行时滚动到该button,并在appium检查器中启动屏幕,我find了该button的完整xpath。 我已经尝试了各种滚动,触摸,并从networking驱动器文档的刷卡方法,但没有什么是显而易见的,我已经离开了蓬松…

那么如何访问不在屏幕上的button呢?

我敢肯定它的一些世俗的细节。 谢谢!

尝试使用下面的滚动function来滚动使用尺寸

  public void scroll() throws IOException { Dimension dimensions = driver.manage().window().getSize(); System.out.println("Size of Window= " +dimensions); int scrollStart = (int) (dimensions.getHeight() * 0.5); System.out.println("Size of scrollStart= " +scrollStart); int scrollEnd = (int) (dimensions.getHeight() * 0.2); System.out.println("Size of scrollEnd= " + scrollEnd); driver.swipe(0,scrollStart,0,scrollEnd,1000); } 

然后使用您的定位器策略来查找元素

我使用node.js来testing反应原生的应用程序解决这个问题。 appium node.js示例代码具有滚动function。首先,您需要导入所有导入的示例。然后是代码:

 it("should scroll", function () { return driver .elementByXPath('//android.widget.TextView[@text=\'Animation\']')//change your element which doesn't cover it. .elementsByXPath('//android.widget.TextView') .then(function (els) { return Q.all([ els[7].getLocation(), els[3].getLocation() ]).then(function (locs) { console.log('locs -->', locs); return driver.swipe({ startX: locs[0].x, startY: locs[0].y, endX: locs[1].x, endY: locs[1].y, duration: 800 }); }); }); }); 

祝你好运 !!