Dennis Pinto
Dennis Pinto

Reputation: 1

I am unable to fetch iOS Native App table child elements using Python-Appium

I am a beginner with appium & python, and have been trying to automate a native app. I have a XCUIElementTypeTable load with a couple dozen XCUIElementTypeCell elements under it. When I try to fetch the table contents i.e. XCUIElementTypeCell element so I can verify a specific child element (Pending tag) in each XCUIElementTypeCell element and if they exist, ignore the type cell and move to the next element and perform some actions in a loop but somehow I am unable to grab the contents of the table and hence unable to loop over to the next element.

Appium Screenshot showcasing presence of XCUIElementTypeTable and XCUIElementTypeCell

This is the block of code I have written to perform the actions, the below code simply fails to identify the child elements and thus fails in /locating the pending tag:

def CompleteJob(self):  
    print('Starting CompleteJob')  
    WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, 'HomeIcon'))).click()  
    WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, 'New'))).click()  
    print('Looking for Table')  
    select_table = WebDriverWait(self.driver, 20).until(EC.presence_of_all_elements_located((AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeOther[`name == "Content View"`]/XCUIElementTypeOther/XCUIElementTypeTable')))  
    # select_table = WebDriverWait(self.driver, 20).until(EC.presence_of_all_elements_located((AppiumBy.CLASS_NAME, 'XCUIElementTypeTable')))  
    if not select_table:  
        print('No table found')  
        return  
    print(f"Found {len(select_table)} tables, selecting the first one.")  
    table = select_table[0]  
    print('Looking for elements')  
    # elements = table.find_elements(AppiumBy.XPATH, '//[@type="XCUIElementTypeCell"]')  
    elements = table.find_elements(AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeOther[`name == "Content View"`]/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell')  
    print(f"Found {len(elements)} cells in the table.")  
    if not elements:  
        print("No elements found.")  
        return  
    # elements = select_table.find_elements(AppiumBy.XPATH, '//XCUIElementTypeTable/XCUIElementTypeCell')  
    # elements = select_table.find_elements(AppiumBy.XPATH, '//[@type="XCUIElementTypeCell"]')     
    for index, element in enumerate(elements):  
        print(f"Processing cell {index + 1}/{len(elements)}")  
    # for element in elements:  
        pending_elements = element.find_elements(AppiumBy.XPATH, '//XCUIElementTypeStaticText[@name="Pending"]')  
        if pending_elements:  
            continue  
        try:  
            sleep(2)             
            clickable_element = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable(element))  
            clickable_element.click()  
            WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeButton[`name == "START JOB"`]'))).click()  
            WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, 'Accepted Jobs'))).click()  
            WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, 'Job List Tab - In Progress'))).click()  
            WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeOther[`name == "Content View"`]/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]'))).click()  
            WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeButton[`name == "COMPLETE JOB"`]'))).click()  
            WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, 'Accepted Jobs'))).click()  
            WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((AppiumBy.ACCESSIBILITY_ID, 'Job List Tab - Completed'))).click()  
            WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((AppiumBy.IOS_CLASS_CHAIN, '**/XCUIElementTypeOther[`name == "Content View"`]/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[1]'))).click()  
        except (NoSuchElementException, StaleElementReferenceException) as e:  
            print(f"Error interacting with element: {e}")  
            continue

Upvotes: 0

Views: 40

Answers (0)

Related Questions