Skip the item that doesn't exist

Hybrid application
I have 3 items
When logging in, sometimes there is an item that does not exist. I want to correct the error and not stop the program

MobileElement el2 = (MobileElement) driver.findElementByAccessibilityId(“1”);;
MobileElement el2 = (MobileElement) driver.findElementByAccessibilityId(“2”);;
MobileElement el2 = (MobileElement) driver.findElementByAccessibilityId(“3”);;

If element number 1 does not exist, I want it to read element number 2, and if it does not exist, it reads number 3 and don’t stop program

wrap your each findElement inside if condition, perform operation only when true. like
if ((MobileElement) driver.findElementByAccessibilityId(“1”)){
(MobileElement) driver.findElementByAccessibilityId(“1”);;

1 Like

Sorry, I wrote wrong code
Please write the command for the following code in full

	MobileElement el1 = (MobileElement) driver.findElementByXPath("1");;

	MobileElement el2 = (MobileElement) driver.findElementByAccessibilityId("2");;

	MobileElement el3 = (MobileElement) driver.findElementByXPath("3");;

	MobileElement el4 = (MobileElement) driver.findElementById("4");;