Is there a way to get the corresponding TextView value of a ToggleButton


#1

I have a list view and I’m trying to interact with elements that all have the same id and index values. Most items in the list view are a list view in itself with TextView and ToggleButton. I want to be able to read and click on certain items regardless of where they are in the list, i.e., without expecting them to be in a certain order. I have the following code and I want to find a way to implement if @settings_switches[i]'s corresponding TextView reads Auto Reload'. Is there a way to find the corresponding TextView value of a ToggleButton?

I’m using Ruby, uiautomator2 and platform is Android.

def is_auto_reload_enabled
    @settings_switches = find_elements(id: 'settings_switch')
    (0.. @settings_switches.length).each do |i|
     #  if @settings_switches[i]'s corresponding TextView reads Auto Reload'
          expect(@settings_switches[i].attribute('checked')).to be true
       end
    end
end