I am trying to launch an Android application on a device using Appium and Desired capabilities, but I am facing difficulty in navigating to elements that are not currently visible

When using Appium and Desired Capability to launch an Android application on a device, I encountered difficulty navigating to elements that are not in the screen view of the same page. Attempting to use JavaScriptExecutor proved to be incompatible with Appium code. Even after using UIAutomator viewer to identify objects, only those within the screen view were recognized. It seems necessary to scroll down to the end of the page to identify out-of-view objects, but even attempts with Keys.END and Keys.ARROW_DOWN have been unsuccessful due to compatibility issues with Appium code.

Answer №1

To ensure that an element is visible before interacting with it, it is recommended to use a combination of swiping down. For example:

    HashMap swipeObject = new HashMap();
    WebElement we = driver.findElement(By.xpath("/relative"));
    Dimension screenSize = driver.manage().window().getSize();
    Double screenWidth = Double.valueOf(String.valueOf(screenSize.getWidth())) / 2;
    Double screenHeight = Double.valueOf(String.valueOf(screenSize.getHeight())) / 2;
    swipeObject.put("startX", (screenWidth));
    swipeObject.put("startY", screenHeight + 100);
    swipeObject.put("endX", (screenWidth));
    swipeObject.put("endY", (screenHeight));
    swipeObject.put("duration", 1.0);
    driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
    
    while (!elementPresent(driver, by, 2)) {
        js.executeScript("mobile: swipe", swipeObject);
        Thread.sleep(1000);
    }
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
}

Answer №2

1) Navigate to the Android sdk folder and open Tools, then run uiautomatorviewer.bat 2) Click on the device icon after UI Automator viewer launches 3) Explore the properties of the captured application screen page Note: The properties can only be viewed using the screenshot method with UI automator

Answer №3

I'm seeking a solution on how to scroll down on a device, despite already utilizing UIautomatorviewer. Currently, only elements that are within the screen view can be identified on the device. While it works fine on the emulator when the application fits the size of the emulator screen, objects that are out of view within the screen cannot be identified when the emulator size is reduced. I have also found that JavascriptExecutor is not compatible with appium code, and using Keys.END and Keys.ARROW_DOWN doesn't allow me to identify objects that are off-screen. If anyone knows how to overcome this issue, please share your insights.

Answer №4

With the latest version of Appium, swipe functionality should now be working smoothly for you. If you're looking to take it a step further and have specific scrolling in certain areas, there's a bit more involved, but here's a Java snippet to help you get started:

public void swipe(Double startX, Double startY, Double endX, Double endY, Double duration) {
    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, Double> swipeObject = new HashMap<String, Double>();
    swipeObject.put("startX", startX);
    swipeObject.put("startY", startY);
    swipeObject.put("endX", endX);
    swipeObject.put("endY", endY);
    swipeObject.put("duration", duration);
    js.executeScript("mobile: swipe", swipeObject);
}

When it comes to Android, there isn't a distinction between an element being present or visible – both are treated as true or false. On iOS, however, the system is able to detect when elements are just off-screen and will auto-scroll to them when clicked or tapped. This can make writing tests a bit more challenging as you may need to manually scroll and verify if an element is there before proceeding with the next action.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Converting to Typescript resulted in the absence of a default export in the module

I converted the JavaScript code to TypeScript and encountered an issue: The module has no default export I tried importing using curly braces and exporting with module.exports, but neither solution worked. contactController.ts const contacts: String[ ...

Adjust the position of an object in Three.js based on the scale of another object

Sharing a helpful solution for a recent problem I faced in case it can assist someone else. Imagine you have a House object with a Chair inside it positioned in a particular spot. If you scale the House's size by 2, the Chair will no longer be in the ...

How can you make a select list appear or disappear based on the selection made in another select list?

I currently have a select list set up like this: https://i.sstatic.net/o730z.png What I would like to achieve is for the second select list to only appear once a selection or change has been made in the first select list. Additionally, when a selection o ...

Controlling Navigation Bar State

Looking to enhance my app by implementing state management for better flexibility. In essence, my app is a React web app integrated with Tableau dashboards. I aim to have specific routes (each containing specific dashboards) dynamically populated in the ap ...

Retrieve data from a JavaScript function that specifies the country, state, city, and locality, providing a complete address in a Spring MVC application

I need to include country, state, city, and the remaining address if available. However, I am not well-versed in using Google API with JavaScript. Currently, I am utilizing a pre-existing JavaScript function that populates the full address in a textbox aft ...

Invoke a class method once the Promise has been successfully resolved

I'm facing an issue with my simple class class A{ constructor(){ this.loadComponents().then(function(values) {callbackOnLoad();}); } callbackOnLoad(){ //do some things } loadComponents(){ ... return Promise.all([p1,p2,p3,p4,p ...

What is the most effective method for deleting outdated messages or posts from a collection?

I'm facing a challenge on this website that prioritizes answers over discussions. I need guidance on how to effectively handle the removal of old messages stored in a collection, considering the high volume of messages involved. Currently, my approac ...

What is the process for activating namespacing on a VueX module that has been imported?

I am currently utilizing a helper file to import VueX modules: const requireModule = require.context('.', false, /\.store\.js$/) const modules = {} requireModule.keys().forEach(filename => { const moduleName = filename ...

Checking the successful loading of JSON data in Angular2+ by following these steps:

I am struggling to write a test for an Angular method that loads the contents of a locally stored JSON file featuring an array. test.ts (trimmed for brevity) describe('MyComponent', () => { beforeEach(async(() => { TestBed.configureT ...

JavaScript reference problem when copying

Initially, I create a raw array by using the following initialization: $scope.rawUsers = angular.copy($scope.users); Subsequently, I make modifications to the data like so: function filterUsers(searchString, onlyMine) { $scope.users = []; _.find($scop ...

How can I make text automatically resize within a fixed DIV based on the length of the text?

What's the best way to handle text in a fixed width and height DIV that can vary in length? I'm okay with reducing the size of the text when it overflows, but how can I make that happen? Any advice would be appreciated. Thanks! ...

Modify the text on a button in ReactJS upon clicking

I am trying to change the text of a button when it is pressed. My goal is to achieve something similar to this example: https://codepen.io/gaearon/pen/xEmzGg?editors=0010, but I am having trouble getting my code to work (I'm new at this). class Obje ...

Steps for removing an item from an array using lodash

I have an array containing objects and I am looking to remove specific items based on certain conditions. Can someone guide me on how to achieve this using the lodash map function? Example: [{a: 1}, {a: 0}, {a: 9}, {a: -1}, {a: 'string'}, {a: 5 ...

Implementing bcryptjs with NodeJS using ES6

Having trouble incorporating the bcryptjs package into my React project. Currently encountering the following error: Could not find a declaration file for module 'bcryptjs'. ‘…/node_modules/bcryptjs/index.js' implicitly has an 'any ...

Alter the shape of the semi-circle to be more elongated and ellipt

Check out my jsfiddle: http://jsfiddle.net/c4upM/103/ I have managed to create a gray arc and a blue/green arc. My goal is to make these arcs more Elliptic, like this: However, my attempts have not been successful so far. I came across this example: h ...

Android SIP Class throws an Exception while invoking SipProfile.Builder

Encountering an issue while trying to create a Builder object. Here is the code snippet: SipProfile.Builder builder = new SipProfile.Builder("address","username"); The error message states: Unhandled exception: java.text.ParseException This example i ...

Fragment A's button is within Fragment B, causing a change in the layout

In the application, there is a single Activity (MainActiviy.java) + Fragments A, B, C, D etc .... When in Fragment A of the Activity and wanting to switch to Fragment B, the challenge arises as the button for switching is in Fragment A. Previously, buttons ...

What term is used to describe this in recursion?

I am trying to understand the concept of reversing a linked list and I stumbled upon a peculiar scenario in which a recursive function doesn't "return" but instead just calls itself. It seems that the function processes data backwards after the recurs ...

Even though I am attempting to submit a form without refreshing the page using Ajax, it is still causing

I've searched high and low, read through numerous examples on various forums, and attempted to find the solution to my query but unfortunately, it still eludes me. Here's the particular scenario I'm facing: Main.php The main.php page featu ...

String values should determine whether a checkbox is checked or not

When retrieving data from LocalStorage, my code looks like this: angular.module('madMeApp').controller('campaignInDetails', function($scope) { var campaignToShow = JSON.parse(localStorage.getItem("CampaignDetails")); $scope.selecte ...