Tried to click on Alert element

Hello
I tried to click on the Pair / Cancel on that Alert and nothing happend, in other case I tried it with regular element and it is return the text but not the Cancel / Pair

xml
The function of clicking in the element is:

    // function to click on element in alert
public boolean clickInAlertElement(WebElement elem) {
    try {
        wait = new WebDriverWait(getDriver(), 5);
        wait.until(ExpectedConditions.alertIsPresent());
        elem.click();
        return true;
    } catch (Throwable t) {
        return false;
    }
}

Thank you

https://appiumpro.com/editions/31-automating-custom-alert-buttons-on-ios

Thank you, is it alert first of all? Second, the link said about what is the label of the buttons and than click according to the link but I need to get the message and test it and according to the text, to decide on what to click, how to do it

  1. image
  2. your functions taps on something NOT predictable. alert may have 1,2,3,4,5… buttons. What button you trying to tap in your code?
  1. so it’s interest because it works even when I just clicked sometimes on cancel / pair not relate to the alert, it works
  2. I pass to the function the button itself, but still no work.
    so what is the way to know what is written in the alert? and according to the text, to select the options? because I didn’t succeded get the text from it

These thing working in other thread and the prints are working, just the clicking and the alert thing is not working ,

What button you pass when alert has many buttons?

Get button by text instead by any way mentioned Unable to accept iOS permission alerts from appium automation code

I first of all need to get the text, after getting the text from the alert if it contains BT I don’t want to connect, I cancel it, else I paired it, so I need to get the text in the alert first of all and than just click cancel or pair

and? what problem? not clear. you have alert. you got it text. you have it buttons…

That’s the thing, I don’t get the alert, and I didn’t succed to click on the buttons

Just search for alert as for usual app elements.

And than? (it’s the element that is marked at the picture as far as I understand)

Correct. Find main alert element and inside get it title element and buttons.

I did getText() and didn’t get the text on the element above, and the buttons too…thats the issue

How you looking for title and buttons? Code you posted does not do it. You should look as for usual app element e.g. driver.findElement…

after I already have the element from above

 // function to click on element in alert
    public boolean clickInAlertElement(WebElement elem) {
    try {
        wait = new WebDriverWait(getDriver(), 5);
        wait.until(ExpectedConditions.alertIsPresent()); 
        return true;
    } catch (Throwable t) {
        return false;
    }

}
elem.getText()
And than if text contains the Bluetooth I need so Pair, else, cancel
But I didn’t get the text and as far as I saw It is not in the element that you see at the picture above

Cause this element is alert container where inside are other elements like title, buttons and so on.

Ok , So what I need to do than?

I mentioned several times look for alert title and button names as for usual app elements. Find it locators. Once in your above code alert appeared get it title and button texts as usual you do with other elements.

In appium gui you may find it locators.

That’s is going with no succed, even the text I don’t get with getText, maybe it’s related to the that that it is other Thread than the main thread?

Write your code and share page source when this alert visible.