This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Find xpath that doesn't have specific child

How can I select objects, that don't have a specified child? For example, I need to find objects, that don't have resource-id "btn-add-remove", in example below is container[2].

MobileObject[@resource-id='container']

MobileObject[@resource-id='cardView']

MobileObject[@resource-id='btn-add-remove']

MobileObject[@resource-id='tv_menu_title']

MobileObject[@resource-id='container'][2]

MobileObject[@resource-id='cardView']

MobileObject[@resource-id='btn-add-remove']

MobileObject[@resource-id='tv_menu_title']

The Xpath that I have tried are

- MobileObject[@resource-id='cardView or @resource-id='tv_menu_title' and not @resource-id!='btn-add-remove']/ancestor::MobileObject[@resource-id='container']

- MobileObject[@resource-id='container']//MobileObject[@resource-id='cardView or @resource-id='tv_menu_title' and not @resource-id!='btn-add-remove']

both resulted in container1

Parents
  • 0  

    If you need to find all the objects, you should be able execute a "findAll" with either of the following locators:

    //MobileObject[@resource-id='container']//MobileObject[@resource-id!='btn-add-remove']

    //MobileObject[@resource-id='container']//MobileObject[not(@resource-id='btn-add-remove')]

    Silk Test should return all objects that match the above locators regardless of indexing. The best way to test this is with the locator spy and validating the locator, which should tell you how many objects match the specified locator.

    -Robert

Reply
  • 0  

    If you need to find all the objects, you should be able execute a "findAll" with either of the following locators:

    //MobileObject[@resource-id='container']//MobileObject[@resource-id!='btn-add-remove']

    //MobileObject[@resource-id='container']//MobileObject[not(@resource-id='btn-add-remove')]

    Silk Test should return all objects that match the above locators regardless of indexing. The best way to test this is with the locator spy and validating the locator, which should tell you how many objects match the specified locator.

    -Robert

Children