In Our case we have multiple items in multiple rooms

Unable to find element for multiple items in multiple room ex:
10 rooms with 2 items in each room
i wrote script like as bellow

Go to room1

find_element(xpath: ‘//[@id=“1”]/img’).click
#get items
find_element(xpath: '//
[@id=“1_xyz1_Switch_F1”]/img’).click
find_element(xpath: ‘//[@id=“1_xyz1_Switch_F2”]/img’).click
driver.navigate().back()
#Go to room2
find_element(xpath: '//
[@id=“2”]/img’).click
#get items
find_element(xpath: ‘//[@id=“2_xyz2_Switch_F1”]/img’).click
find_element(xpath: '//
[@id=“2_xyz2_Switch_F1”]/img’).click
driver.navigate().back()
#go to room3
find_element(id: ‘3’).click
#get items
find_element(id: ‘3_xyz3_Switch_F1’).click
find_element(id: ‘3_xyz3_Switch_F2’).click
driver.navigate().back()
#go to room4
find_element(id: ‘4’).click
#get items
find_element(xpath: ‘//[@id=“4_xyz4_Switch_F1”]/img’).click
find_element(xpath: '//
[@id=“4_xyz4_Switch_F2”]/img’).click
driver.navigate().back()

so on …

In this case it will perform action first room items after finishing it its redirecting to login page says element not found error [ '//*[@id=“2”]/img even i use sleep also still getting same
can any one help me.