2

I'm testing a native Android app and need to click on a button that is off the bottom of the screen. I've seen tons of examples of this using Java and Javascript but I'm using Node.js and nothing seems to work. I'm pretty new to this stuff and have wasted far too much time on something so simple.

For example to click on an onscreen element this works:

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

Also the full xpath works for onscreen elements - in this case:

    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();
            });

I found the full xpath for this button by scrolling to it while the test was running and firing up the screen in appium inspector. I've tried various scroll, touch, and swipe methods from the webdriver docs but nothing is available so apparently I've wandered off the ponderosa...

So how can I access a button that is not on the screen?

I'm sure its some mundane detail. Thanks!

sluggo
  • 46
  • 5
  • after scrolling does it shows up the element in screen – karthick23 Jul 15 '16 at 11:59
  • there is no scrolling function that works from what I can tell. If I can get the screen to scroll I'm sure it will work since the hang up is the fact the element is not on the screen. – sluggo Jul 15 '16 at 13:19

2 Answers2

0

try the below scroll function to scroll using dimensions

 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);   }

and then use your locator strategy to find the element

karthick23
  • 1,313
  • 1
  • 8
  • 15
  • 1
    I'm using node.js (not Java) for the testing script so I'm pretty sure this isn't going to work. – sluggo Jul 18 '16 at 16:30
0

I'm use node.js to test react native app solve this problem . The appium node.js sample code have scroll feature.First,you need import all what sample imported.Then there's the code:

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
          });
        });
      });
  });

good luck !!

ohbo
  • 21
  • 1