Sate Nheehan Sate Nheehan - 1 year ago 126
Swift Question

XCUITest Multiple matches found error

I am writing tests for my app and need to find the button "View 2 more offers" there are multiple of these buttons on my page but I would just like to click on one. When I try this, an error comes saying "Multiple matches found"
So the question is, what ways can I go around this so my test will search and tap on only one of the buttons called "View 2 more offers".

Here is my current code

let accordianButton =["View 2 more offers"]
if accordianButton.exists {

Answer Source

You should use a more elaborated way to query your button, since there is more than one button who's matching it.

    // We fetch all buttons matching "View 2 more offers" (accordianButtonsQuery is a XCUIElementQuery)
    let accordianButtonsQuery ="View 2 more offers")
    // If there is at least one
    if accordianButtonsQuery.count > 0 {
        // We take the first one and tap it
        let firstButton = accordianButtonsQuery.elementBoundByIndex(0)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download