I have a list of devices on my app screen. Each webelement that represents a unique device has 2 children:
- (unique) device name
- On/Off status
Parent devices have the same id, so the way to select the correct device is to go through the children and check that device_name.text is the name I want.
I'm trying to write a functions that evaluates on off status for a specific device name without using xpath
def check_on_off_status(device_name:WebElement):
device = device_name.find_element_by_xpath('..') # we find the parent from device_name, and navigate from there
# power_status_element = get_child(device,power_status_id)
# return power_status_element.enabled
But I'm getting an exception when evaluating the xpath expression. How can I get the parent node if I only have the element?
Edit:
Parent (Device) Xpath
/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout /android.widget.FrameLayout/android.widget.LinearLayout /android.widget.FrameLayout/android.view.ViewGroup /androidx.viewpager.widget.ViewPager /androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout /android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView /android.view.ViewGroup[1]/android.widget.FrameLayout /android.view.ViewGroup/android.view.ViewGroup
Device Name Xpath: /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.TextView[1]
On/Off Icon (device name sibling) Xpath:
/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/androidx.viewpager.widget.ViewPager/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.view.ViewGroup[1]/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.widget.ImageView