Efficient way to navigate through a list in an android app using Appium and Python

Looking for a way to scroll through a list in an Android app using Python? I have a code that works, but it keeps scrolling until it finds the specified element 'India'. However, I only want it to scroll once.

self.driver.find_element_by_android_uiautomator('new UiScrollable(newUiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().text("India").instance(0));')

I also tried another approach:

el1 = self.driver.find_element_by_xpath("//*[@resource-id = 'resource-id' and @index ='1']")
el2 = self.driver.find_element_by_xpath("//*[@resource-id = 'resource-id' and @index ='0']")
self.driver.scroll(el1, el2)

While this method does scroll through the list, it continues scrolling for a long time. What I actually need is to move to each and every element in the list individually.

If you have any suggestions on how to achieve this one-time scroll through the list, please let me know!

Answer №1

The code I used worked perfectly for me. I simply utilized the touch action by pressing and releasing, but since I only needed to scroll once, I removed the release() part and it worked flawlessly :)

el1 = self.driver.find_element_by_xpath("<xpath>")
el2 = self.driver.find_element_by_xpath("<xpath>")
action = TouchAction(self.driver)
action.press(el1).move_to(el2).perform()

If anyone else wants to achieve the same result, they can follow these same principles.

Answer №2

Just discovered a neat trick - all you have to do is swipe from the bottom to the top while the test is in progress. I tried it and it really works like magic!

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

Loop through a list in Python and subtract values using a for

I need help with performing simple calculations in a for loop. I have two columns in the example file below. Column 1 represents date-time-hr-min-ss, and column 2 contains a value. My goal is to iterate through the file and calculate the difference between ...

Discover an input field using xpath that does no have a specified value attribute

Consider this HTML: <input id="test" value="my text" /> It's simple to target the input element using XPath with a query like: input[@value="my text"] But what if the original HTML appears like this: <input id="test" /> Despite not h ...

Enhancing the django admin group with an additional field

I am seeking guidance on how to add a single field to a group of fields within a fieldset in DjangoAdmin. Currently, I have the following setup: class SecretarioAdmin(UserAdmin): model=Secretario def get_fieldsets(self, request, obj=None): ...

Verifying a tooltip value for a specific section (bar) on a bar chart using Selenium WebDriver

Is there a way to extract the value 31732 from the margin (sum) tooltip for Electrolux vendor in the bar chart shown below? https://i.stack.imgur.com/CIgIW.png The following HTML provides the code for the div enclosing this value. Your advice on how to ...

Load the PATCH information utilizing Marshmallow without confirming the absence of fields

I am currently working on setting up a PATCH route for the given SQLAlchemy model and Marshmallow-SQLAlchemy schema. My goal is to be able to update either the description, address, or both fields. However, I have encountered an issue where if I only sen ...

What is the best way to combine string columns with NaN values?

I have a dataset that is structured as follows: import pandas as pd import numpy as np mydict = { 'col1' : ['a', 'b', 'c'], 'col2' : ['d', np.NaN, 'e'], 'col3' : [ ...

Leveraging python's BeautifulSoup library, one can easily implement HTML selection

Recently, I've started diving into Automate the Boring Stuff and exploring how to create my own programs. Currently, I'm experimenting with beautiful soup's 'select' method in order to extract the value '33' from this cod ...

org.openqa.selenium.WebDriverException: Failed to start WebDriver server within the expected time frame while using Selenium in conjunction with Java

I've exhausted all the solutions provided in Stackoverflow threads. My Java Selenium tests are running on a remote slave through Jenkins. The strange thing is that only the first test runs successfully and opens the browser, while all subsequent tests ...

Troubleshooting Chrome driver version conflict with Selenium and PyInstaller in Python

Currently, I am utilizing the Google Chrome driver to automate various functions. To execute it, I have included this line in my code: driver = webdriver.Chrome(ChromeDriverManager().install()) Surprisingly, everything works smoothly when I run the progra ...

Issue encountered with Pytest Selenium due to elem.send_keys() causing a TypeError stating that an object of type 'NoneType' does not have a length

Struggling to input data into a login textbox using 'send_keys' function and encountering an error.. def wait_for_element(selenium, selenium_locator, search_pattern, wait_seconds=10): elem = None wait = WebDriverWait(selenium, wait_secon ...

Tips for specifying a function argument as a subclass of a specific class in Python

Is it possible to specify an argument of a function as an instance of any class, taking into account only the inherited classes that I have specified? Union is similar in concept, but it functions like OR, allowing for instances of A or B or any inherited ...

"Exploring the world of randomized values with Tensorflow

As I venture into the world of deep learning and tensorflow, I find myself faced with some questions. Following the Tutorial and the Getting Started guide, I have created a DNN with hidden layers as well as a simple softmax model. I utilized the dataset f ...

When utilizing .to_json to convert a data-frame into JSON format, it can cause issues with datetime data formats

I have a 4 column dataframe with only one row of data. To send this data to an API via a POST request, I convert the row to JSON using the following code: data = local_materials.loc[local_materials['id'] == apicounter] Within the dataframe, one ...

Transforming a JSON with nested elements into a CSV file using Python

I need assistance with converting a nested JSON to a CSV file. The JSON data is being retrieved from a Rest API. The CSV file should have the following fields: daterange_start, daterange_end, clicks, impressions, pivotvalues. I am a beginner in Pyt ...

Adjustable ember count within Intercom HTML using Selenium and Python

My goal is to automate tasks at my workplace, but I am facing some challenges. Due to the lack of admin access on my work Intercom App, I have resorted to using Selenium. I need to input "Hey" into the chat box on Intercom and send the message successfull ...

Utilizing Protractor and Teamcity in tandem with Grunt for seamless

Currently, I'm facing a challenge in setting up Protractor tests on Teamcity using Grunt. I have attempted to configure the runner through the command line but haven't had any success so far. While I can successfully execute protractor with Gru ...

Run a Firefox Browser within a Docker Container for Selenium testing purposes

Currently, I am utilizing a Java Application to manage an automated GUI test on a FF-Browser using the Selenium WebDriver Library. This application fetches test cases from a database and runs them based on specified code logic. For example, when the appli ...

Two Players Engage in Dice Roll Challenge

A programming challenge involves a code that allows two players to roll dice by typing 'roll' for each of their turns. However, there is an issue in the code where if they don't input 'roll' correctly, it proceeds without prompting ...

The IWebElement Text Property now includes support for displaying emojis

OpenQA.Selenium.IWebElement.Text When accessing the Text Property and the HTML inner text is ":x:", you will receive ":x:". If the Text is ":white_check_mark:", the Return Value will be ":white_check_mark:". I searched for various Emojis and Unicode Ref ...

Error: The 'geckodriver' executable must be located within the PATH directory

Recently, I encountered an issue while trying to deploy a Flask app on a production server using Firefox Geckodriver. The server runs on Ubuntu 18.04 with nginx installed and the application itself is a image detection Flask Python program. Oddly enough, t ...