0

I am trying to automate long press action followed with clicking on the static shortcuts available in context menu.

Details:

language - python

automation lib - appium

android app - Youtube

static shortcut - Subscriptions

Sample Image of what I want to click - enter image description here

I am able to perform longpress action on the Youtube App but unable to click on the shortcut( for example - Subscriptions) available in context menu.

Below is the code :

from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
import time
import os
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import StaleElementReferenceException
from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.action_chains import ActionChains


def reopen(android_package="com.google.android.youtube", udid="udid_xxx"):
        """
        Creating a new driver object
        """
        time.sleep(2)
        desired_caps = {
            "deviceName": "MI",
            "platformName": "Android",
            "version": "13",
            "automationName": "Appium",
            "noReset": True,
            "chromedriverExecutable": os.path.join(os.getcwd(), "chromedriver.exe"),
            "showChromedriverLog": True,
            "chromeOptions": {
                "androidPackage": android_package,
                "w3c": False
            },
            "autoGrantPermissions": True,
            "newCommandTimeout": 3000,
            "wdaStartupRetryInterval": 20000,
            "wdaStartupRetries": 4,
            "adbExecTimeout": 20000,
            "ignoreHiddenApiPolicyError": True,
            "udid": udid
        }

        # Create web driver
        driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)

        wait = WebDriverWait(driver, timeout=5)
        by = AppiumBy.XPATH
        # searching for YouTube app 
        value = "//android.widget.ImageView[@content-desc='YouTube']"
        element = wait.until(EC.element_to_be_clickable((by, value)))

        # Performing logn_press action on YouTube app
        actions = TouchAction(driver)
        actions.long_press(element).perform()
        time.sleep(5)
        # Pressing the  Subscriptions option in context menu
        tap_element = driver.find_element(AppiumBy.XPATH, "//android.widget.TextView[@text='Subscriptions']")
        #element = wait.until(EC.element_to_be_clickable((AppiumBy.XPATH, tap_element)))
        print(tap_element.is_displayed())  # output - True
        print(tap_element.text)  # output - Subscriptions
        print(tap_element.is_enabled) # output - <bound method WebElement.is_enabled of <appium.webdriver.webelement.WebElement 
                                      #  (session="e811b0a3-c59f-4042-9613-ba650fae1d21", element="00000000-0000-0a1b-ffff-ffff000019c8")>>

        tap_element.click()  # Not working 


if __name__ == '__main__':
     reopen()
workspace
  • 368
  • 1
  • 6
  • 16

1 Answers1

0

You didn't really explain how its "not working". Do you get an error - or does it just fail to click on the option?

If the problem is the second - I'd try to get center coordinates of tap_element and tap on that. You could also try tapping on the icon associated with that choice instead via

"//android.widget.TextView[@text='Subscriptions']/preceding-sibling::android.widget.ImageView".
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129