在appium中根据多个条件查找元素

find element based on multiple condition in appium

我正在创建一个 Ionic 应用程序,它针对不同 os 具有不同的结构,因此我想使用多个查找元素方法定位一个元素并执行测试。如何实现这些基于条件的元素目标。

if (first input box){
//do this
}

if else (input place holder "userName"){
//do this
}

if else (id with "userName"){
//do this
}

else{
//failed
}

也许只是 try/except?

Try:

   el1 = self.driver.find_element_by_id('ID')
   //do this

Except NoSuchElementException:
   pass

Try:

   el2 = self.driver.find_element_by_id('ID2')
   //do this

Except NoSuchElementException:
   pass

Try:

   el3 = self.driver.find_element_by_id('ID3')
   //do this

Except NoSuchElementException:
   self.faile('elements not found')

或 "isDisplayed":

el1 = self.driver.find_element_by_id('ID')
if el1.is_displayed():
//do this