Tips for partitioning an element using Selenium and Appium when it lacks a distinctive ID, class, package, or resource identifier:

I am currently trying to determine if I am receiving the expected response from a text message. In order to do this, I need to access the text view of the incoming message. The challenge I am facing is how to distinguish between the received text and the sent text.

The first image of the UI selector highlights the sent text, displaying its ID, class, package, and resource ID (which is out of frame).

In the second image of the UI selector, the received text is highlighted, showing its ID, class (out of frame), package, and resource ID (out of frame).

All attribute values match except for the text value. How can I make Appium recognize which text to check for? I was thinking of something that involves accessing an element within another element. The code I assume would look like this:

await driver.waitForElementById('com.android.mms:id/msg_list_item_recv', 30000, function (err, data) {})
        .elementById('com.android.mms:id/text_view', function (err, data){})
        .textPresent('key text value', function (err, data) {});

Any assistance on this matter would be highly appreciated.

Answer №1

One way to improve the code is by asking developers to update the ID of the send text to ensure a clear distinction from received text. Currently, both sent and received text share the same ID. If changing the ID is not feasible, another approach could be considered.

@FindBy(id = "com.android.mms:id/text_view")
    private List<WebElement> messagelist;

for (int i=0;i<messagelist.size();i++) 
{ 
    if(messagelist.get(i).gettext().contentEquals("sendtext"))
    {
       // The next element (i+1) represents the received text
        messagelist.get(i+1).gettext().contentEquals("recievedText")
    }
}

Answer №2

To determine whether a message is received (left) or sent (right), one can compare with their respective bounds...

For illustration purposes, let's consider these two bounds:

Received message

Sent message

With my example, an Xpath representation could be:

"//android.widget.TextView[@resource-id='com.android.mms:id/msg_list_item_recv' and contains(@bounds, '[163,')]"

If an element is positioned at [163,100][100,100], it will be correctly identified. However, a potential issue arises when an element is at [100,100][163,100], as it may be misidentified as received. Therefore, an alternative method without this limitation is recommended...

Another approach to specifically target left messages is as follows:

"//android.widget.TextView[@resource-id='com.android.mms:id/msg_list_item_recv' and not(contains(@bounds, '][942,'))]"

This query will exclude any textview that contains "][942," ensuring accurate identification of left messages.

If you try these methods, please let me know if they are effective.

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

Choosing the perfect item with the help of a material's GridList

I've developed a react-mobx application using Material-UI, and the code structure is similar to this: render() { // defining some constants return ( <div> <img src={selectedPhoto} alt={'image title'} /> < ...

generate code to automatically output the content of a website

I'm in the process of creating a program that automatically navigates to a website and prints a page. Unfortunately, I'm encountering difficulties in getting it to function properly. I've attempted using the selenium chrome driver, but with ...

Breaking Down URLs with JavaScript

I am looking to extract specific portions of a URL and here is my progress so far. <script type='text/javascript'> var query = window.location.pathname.split( '/' ); query = window.location.pathname.split( '.html' ); v ...

Is it possible to use JQuery ScrollTop while in the midst of an animation?

I am facing an issue with resizing containers and scrolling to elements. I have 2 containers that change width dynamically, each containing clickable elements. When a container is clicked, it animates the resize. However, when a clickable element is clicke ...

Having issues with importing Highcharts Gauge using NPM and Webpack

I've integrated HighCharts into a website using vanilla JS, utilizing webpack/npm for module loading and importing. While Spline and Column charts are working perfectly fine, I encountered an issue when trying to add the standard Gauge chart (seen her ...

Scrolling seamlessly on websites with a single page

I am developing a single-page website that uses different section IDs instead of multiple pages. It's functioning properly, but I want to implement smooth scrolling to the sections rather than just statically jumping to them on the page. Jsfiddle: ht ...

The Gson toJson function is appending " " to the end of my property value

I'm having an issue with Gson in Android where it is inexplicably adding a \n to the end of one of my object properties. Can anyone provide some guidance on this? Much appreciated. The object in question is a ticket. When I log the TicketId pro ...

What is the best way to generate a box when a button is pushed?

How can I make a button create a box with text inside it when clicked? <div class="trades"> </div> <button onclick="create()">add</button> Here is the JavaScript function to create the box: function create() { var box = docu ...

Optimal Strategy: Utilizing Spring Boot for Backend Development and jQuery for Frontend Interface

I am currently tackling a project that involves a Spring Boot 2 Backend and a jQuery Frontend. The frontend communicates with the backend by sending Ajax requests to Spring REST controllers in order to interact with database entities. One of the challenge ...

Extract specific data points from external API responses on a webpage crafted in HTML

I require assistance on how to extract individual values from an HTML page. I received a response from the PAYU payment gateway team in HTML format, but I need to retrieve specific attribute values related to the transaction details. Below is the response ...

Obtain the Week Input's Value

Is there a way to store the value of a week input in a variable and then display it in a span? I attempted the following code: <input type="week" name="week" id="week-selector"> <span id="kalenderwoche"> ...

What is the best way to programmatically send commands to Selenium using Python?

Is it feasible to implement a feature in Selenium where Python code can be dynamically entered by the developer during runtime? This would allow for live testing of code on a webpage, such as offset or scrolling, without having to reload the website each t ...

Join the geomarkers in two datasets using connecting lines

I am currently developing a leaflet.js map incorporating two distinct sets of JSON data layers stored as js-files. The first dataset comprises the geographical locations of various newsrooms along with their respective IDs, while the second dataset contai ...

Having difficulty accessing a JSON imported object beyond the FOR loop

I am facing an issue when trying to reference my imported JSON data. The problem arises when I attempt to access the data outside of a FOR loop, resulting in the error message "Uncaught TypeError: Cannot read property 'Tname' of undefined" The f ...

Creating a button in ReactJS with text displayed under an icon

Presently, I am working with a component that looks like this: https://i.stack.imgur.com/qGCwj.png This is the code for the component: import React from "react"; import {withStyles} from "material-ui/styles"; import Settings from "material-ui-icons/Setti ...

Choosing between cjs and esm for a React components library

I'm working on a components library that will soon be published to npm for use in a razzle app. My main query revolves around the best practices for building these packages - should they be built with CommonJS (cjs) or ECMAScript Modules (esm)? And wh ...

Ways to retrieve the data received from an axios.post request in the server-side code

Currently, I am working on a project that involves using React for the frontend and Spring Boot for the backend. However, I am facing an issue with retrieving data that I have sent using Axios from the frontend to the backend. The code snippet below show ...

Experiencing a problem with Datatables where all columns are being grouped together in a single row

After creating a table with one row using colspan and adding my data to the next row, I encountered an issue with the datatables library. An error message appeared in the console: Uncaught TypeError: Cannot set property '_DT_CellIndex' of unde ...

The launch of the hudson:firefox browser in Selenium is unsuccessful when executing Selenium scripts via Hudson

After integrating my Selenium scripts (using JUnit) with Hudson and invoking my job through Ant, I encountered an issue where my scripts were running successfully but the Firefox browser was not opening. It is important to note that I am currently not ut ...

What could be the reason for the scope being empty in my AngularJS application?

I'm new to Angular and I'm currently customizing the tutorial for my app. However, I'm facing an issue with adding routes to my app. The templates are not being read correctly and the controller seems to have some issues as well. In order to ...