Mobile App Element Interaction Methods in UI Automation

  1. Click action: element.click()
  2. Text input: element.send_keys("text_value")
  3. Value setting: element.set_value("new_value")
  4. Clear content: element.clear()
  5. Visibility check: element.is_displayed() returns boolean
  6. Enabled status: element.is_enabled() returns boolean
  7. Selection state: element.is_selected() returns boolean
  8. Attribute retrieval: get_attribute(attribute_name)

Note: Some attribute like 'index' cannot be retrieved through get_attribute() method.

Element Properties and Positioning

Element coordiantes refer to the top-left corner position of the element.

Example Implementation with Xueqiu App


class StockAppTest:
    def setup(self):
        config = {
            'platformName': 'Android',
            'platformVersion': '6.0',
            'deviceName': 'test_device',
            'appPackage': 'com.xueqiu.android',
            'appActivity': 'com.xueqiu.android.common.MainActivity',
            'noReset': True,
            'keepAppData': True,
            'skipSetup': True,
            'keyboardSettings': {
                'unicodeKeyboard': True,
                'resetKeyboard': True
            }
        }
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', config)
        self.driver.implicitly_wait(10)

    def cleanup(self):
        self.driver.back()
        self.driver.quit()


def test_search_feature(self):
    """
    Test case for search functionality:
    1. Launch Xueqiu app
    2. Locate search field
    3. Verify if search is enabled and get name attribute
    4. Print element coordinates and dimensions
    5. Input search term "JD"
    6. Verify visibility of search results
    7. Print success/failure message
    """
    search_field = self.driver.find_element(By.ID, 'com.xueqiu.android:id/tv_search')
    print(f"Enabled: {search_field.is_enabled()}")
    print(f"Position: {search_field.location}")
    print(f"Dimensions: {search_field.size}")
    
    if search_field.is_enabled():
        search_field.click()
        search_input = self.driver.find_element(By.ID, 'com.xueqiu.android:id/search_input_text')
        search_input.send_keys('JD')
        
        result_element = self.driver.find_element(
            By.XPATH, "//*[@resource-id='com.xueqiu.android:id/name' and @text='JD']"
        )
        
        if result_element.get_attribute('displayed') == 'true':
            print('Search successful')
        else:
            print('Search failed')

Tags: appium UI Automation Mobile Testing Android xpath

Posted on Wed, 10 Jun 2026 16:22:19 +0000 by bbaker