Search code examples
seleniumautomated-testsappiumrobotframeworkui-automation

find element based on multiple condition in appium


I am creating an Ionic application which has different structure for different os so i want to target an element using multiple find-element method and want to execute the test. how to achieve these kind of condition based element target.

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

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

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

else{
//failed
}

Solution

  • Maybe just 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')
    

    or something with "isDisplayed":

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