I need to go over a list that takes a package name, search it on the Google Play app to to app info and returns the version number of the app.
i managed to find and return the version number for the first app in my list (com.waze)
but when the loop goes for the second app (com.slack) it gets back the app size.
given that i need to run this code on 300-400 apps. I need a reliable way to find it
here is the code so far
from appium import webdriver
from appium.options.android import UiAutomator2Options
import time
from selenium.webdriver.common.by import By
from appium.webdriver.common.appiumby import AppiumBy
# Create an instance of UiAutomator2Options
options = UiAutomator2Options()
appid = ["com.waze","com.slack"]
for app in appid :
# Set desired capabilities
options.platform_name = 'Android'
options.platform_version = '11'
options.device_name = 'R58M642LZQX'
options.app_package = 'com.android.vending' # Google Play Store's package name
options.app_activity = 'com.google.android.finsky.activities.MainActivity' # Play Store's main activity
options.no_reset = True
options.automation_name = 'UiAutomator2'
# Initialize the driver with the Appium server URL and the options instance
driver = webdriver.Remote('http://localhost:4723/wd/hub', options=options)
print("Session started")
time.sleep(2)
search= driver.find_element(By.XPATH, '//android.view.View[@content-desc="Search Google Play"]')
# Then you would need to iterate through `elements` to find the one you want
search.click()
time.sleep(2)
search_text=driver.find_element(By.CLASS_NAME,'android.widget.EditText')
search_text.send_keys(app)
time.sleep(3)
driver.press_keycode(66)
time.sleep(3)
app_page = driver.find_element(By.XPATH, '//android.view.View[1]')
app_page.click()
time.sleep(5)
about_the_app= driver.find_element(By.XPATH, '//android.view.View[@content-desc="Learn more About this app"]')
about_the_app.click()
time.sleep(3)
driver.find_element(AppiumBy.ANDROID_UIAUTOMATOR,'new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView('
'new UiSelector().text("Version"))')
the last part is to navigate to were "Version" is mention in text and scroll there. the version number element is right next to it and dose not have an individual identifier

I tried to use the Version text element to find the number element by following-sibling xpath
# Locate the "Version" label
version_label = driver.find_element(AppiumBy.XPATH, "//android.widget.TextView[@text='Version']")
# Assuming the version number is the next TextView element, use the following-sibling axis
# This will find the first following sibling that is also a TextView
version_number = version_label.find_element(AppiumBy.XPATH, "./following-sibling::android.widget.TextView[1]")
# Now you can interact with the version_number element, like printing its text
print(version_number.text)
it did not work .
the element also have a parent element, that "Version" text and the number are it's children
Classname = android.widget.LinearLayout (no individual identifier for this element )
try to use this to find the version number element by recommendation of chatgpt
from appium.webdriver.common.appiumby import AppiumBy
# Step 1: Locate the parent LinearLayout
parent_layout = driver.find_element(AppiumBy.XPATH, "//android.widget.LinearLayout[.//android.widget.TextView[@text='Version']]")
# Step 2: Locate the version number within the parent LinearLayout
version_number_element = parent_layout.find_element(AppiumBy.XPATH, ".//android.widget.TextView[2]")
# Optional: Print or assert the found version number
print(version_number_element.text)
this did not work also, the return statement was Waze or Slack aka the first android.widget.TextView element available on the page .
I hope any of you can find a way to reliably get the number for any app i put to the code. Thank you