Impossible to click on element on iOS devices

My stack for mobile automation is Appium + WebdriverIO + TypeScript.
For one on my test I need to click on [Yes Logout] button in this modal:

The button [Yes Logout] has the Accessibility ID and it can be found in the Appium Inspector. But it is impossible to execute default click() on this element.

I have decided to do ‘tap by coordinates’ and used this method:

    async mobileTap(selector: string): Promise<void> {
        const element = driver.$(selector)
        const elementId = await element.elementId
        const { x, y, height, width } = await driver.getElementRect(elementId)
        const xCenter = x + Math.round(x + width / 2)
        const yCenter = y + Math.round(x + height / 2)
        return driver.execute(`mobile: ${driver.isIOS ? 'tap' : 'clickGesture'}`, { x: xCenter, y: yCenter })
    }

In Appium inspector when I selected option ‘tap by coordinates’ and hover over the ‘Yes Logout’ button I see the next x and y coordinates: x = 180 and y = 715. But after calculation of center coordinates using the below method I have got x = 191 (it is ok) , but the y = -4410 . And the element with such coordinates is not found and can not be clicked.

Please, advise, how can I click on the [Yes Logout] button.

There is a problem with this code in the second line. Shouldn’t it be:

const yCenter = y + Math.round(y + height /2)?

I have tried to change it, but was not helped. The main reason that I have the strange value for ‘y’ coordinate directly in the Appium inspector

I recommend bringing that up with your developers. Maybe some problem with app code? At least get some dev eyes on it.

1 Like

In most cases strange values means you are in webView and you made scroll.

In most cases per my expirience you have nothing to do but only switch to web contex.

1 Like

Thanks!
I have tried to switch to WebView context, but I have received only NATIVE_APP context after running this command:

await driver.getContexts()

I have seen that this element has visible: false

Although when I am searching for this element in Appium inspector it was found

can you share whole page source?

// wait 3-5sec after 'Yes Logout' button visible on screen
// Java
System.out.println(driver.getPageSource());

I have added this code:

        const sel = $('~Yes Logout')
        await sel.waitForDisplayed({ timeout: 5000 })
        const source = await driver.getPageSource()
        console.log(source)

But it failed on the row await sel.waitForDisplayed() because the [Yes Logout] button is still not visible after 5 seconds

No matter. Just sleep for 5-10sec after visually button is visible.

Thanks, it was solved already.

Hope you will left an answer what helped you for others …

Yes, sure.
There was an issue for it Appium doesn't find the element in iOS modal window · Issue #854 · facebookarchive/WebDriverAgent · GitHub

For my case the following was helped:
set Accessibility to false for appropriate modal component