# Click on element in alert - ios 15

**URL:** <https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332>\
**Category:** Support\
**Created:** [December 30, 2021, 5:15pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332 "2021-12-30T17:15:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [December 30, 2021, 5:15pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/1 "2021-12-30T17:15:39Z")

</div>

Hello,  
In my real device ios 15.1 I have scenario where I should click on “call…” in popup (Alert), I have tried to use the method to wait for the alert and than click on the element and still it fall where it needs to wait (even for 1 min), the code looks like that:

```
public boolean clickInAlertElement(By elem) {
   try{
      wait.until(ExpectedConditions.alertIsPresent());
       driver.findElement(elem).click();
        return true;
     } catch (Throwable t) {
          return false;
     }
 }

```

also I tried to driver.SwitchTo().Alert().getText(); and I son’t get the text at all

- java
- ios 15.1
- real device

 ![49](https://discuss.appium.io/uploads/default/original/2X/a/a3731bb7d4c6491e28749f9eecc4e8e7a3857bdf.jpeg)

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [December 30, 2021, 6:05pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/2 "2021-12-30T18:05:05Z")

</div>

What does this look like in Appium Inspector? If it’s really an alert, you’ll see this type, “XCUIElementTypeAlert” in the xml.

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 2, 2022, 8:17am UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/3 "2022-01-02T08:17:59Z")

</div>

[here is it](http://iloveformat.com/xml-formatter/?id=01712b2f-39ab-4183-9e9d-a973ade456fa)

@wreed

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [January 2, 2022, 9:26pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/4 "2022-01-02T21:26:35Z")

</div>

Are you sure that’s the right xml? I don’t see an alert element, first of all, but second there is no “Call 9-11”, instead I see this:

```
                                        <XCUIElementTypeStaticText type="XCUIElementTypeStaticText" value="Call 166" name="Call 166" label="Call 166" enabled="true" visible="true" accessible="true" x="84" y="671" width="267" height="24" index="2"/>

```

What is “Call 166”?

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 3, 2022, 5:59am UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/5 "2022-01-03T05:59:07Z")

</div>

@wreed yes thats the right one, it looks like that apple change something and it is not Alert anymore, I saw it yesterday too and open that XML in chrome and look for that in xpath (thats what I suppose to do?) and saw that it is not alert and didn’t obtain something that worked at the code actualy.  
I tried `//XCUIElementTypeStaticText[contains(text(), 'Call')]`

Yes, The 166 same as the 911

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [January 3, 2022, 4:16pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/6 "2022-01-03T16:16:57Z")

</div>

> [@I7210I](#):
>
> look for that in xpath (thats what I suppose to do?)

I don’t use xpath on iOS because it’s too slow, but I know sometimes you can’t avoid it. I don’t know the language you are using but I’d do something like this in Ruby:

```
driver.find_element(:name, 'Call')

```

I’m sure there is something similar in whatever you are using.

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 3, 2022, 4:33pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/7 "2022-01-03T16:33:50Z")

</div>

@wreed  
So i’m using Java  
And there is 2 items on “Call” over there… your method found one?  
And still, it is not overlay or something like these? how it will manage to click on it?

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [January 3, 2022, 5:50pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/8 "2022-01-03T17:50:40Z")

</div>

Here is the documentation on find\_element:

[https://appium.io/docs/en/commands/element/find-element/](https://appium.io/docs/en/commands/element/find-element/)

I obviously can’t code against your app as I don’t have it. But this is why I wanted you to take a look with Appium Inspector. The inspector will give you a lot more information that just the XML, and should help you to see how to access this element.

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 3, 2022, 8:25pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/9 "2022-01-03T20:25:08Z")

</div>

@wreed Thank you, obviously I used the inspector, but as far as I tried with the alert element it didn’t worked (it worked till version 15 of IOS) so maybe it was changed and now I just need to click on it like regular element eventough it is look like alert?

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [January 3, 2022, 9:34pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/10 "2022-01-03T21:34:40Z")

</div>

Yes, from the information that I have that seems like the logical conclusion.

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 4, 2022, 10:41am UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/11 "2022-01-04T10:41:11Z")

</div>

@wreed  
I tried to search for the element and to click on it, when I click on it, it disappear (the two lines), when I click again on the call (The orange one) It calling  
the locator is: `//XCUIElementTypeStaticText[contains(@name,"Call")]`  
what I missing here? (manually it works ok)

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [January 4, 2022, 10:56am UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/12 "2022-01-04T10:56:54Z")

</div>

```auto
// java examples

// el1 and el11 -> find element with text = 'Call 166'. difference with additional condition of 'type'
WebElement el1 = driver.findElement(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND name == 'Call 166' AND visible == 1"));
WebElement el11 = driver.findElement(MobileBy.iOSNsPredicateString("name == 'Call 166' AND visible == 1"));

// el2 -> find element with text contains 'Call'
WebElement el2 = driver.findElement(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND name CONTAINS[cd] 'Call' AND visible == 1"));

```

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 4, 2022, 12:51pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/13 "2022-01-04T12:51:02Z")

</div>

> [@Aleksei](#):
>
> type == ‘XCUIElementTypeButton’ AND name CONTAINS[cd] ‘Call’ AND visible == 1

Thank you, tried them both (each) and they are not work maybe I missed something?

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [January 4, 2022, 12:52pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/14 "2022-01-04T12:52:59Z")

</div>

> [@I7210I](#):
>
> are not work

sounds not clear. element not found or ? tried add simple sleep before (cause this `driver.findElement` is quite fast check)?

try add logs like:

```auto
System.out.println(el.getLocation().x, el.getLocation().y); 

```

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 4, 2022, 12:57pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/15 "2022-01-04T12:57:07Z")

</div>

Just opened the Appium inspector and search with it the elements according to iOSNsPredicateString

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [January 4, 2022, 12:57pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/16 "2022-01-04T12:57:43Z")

</div>

i do not use Appium inspector. try on code.

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 4, 2022, 1:02pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/17 "2022-01-04T13:02:14Z")

</div>

so  
`WebElement el2 = getDriver().findElement(MobileBy.iOSNsPredicateString(“type == ‘XCUIElementTypeButton’ AND name CONTAINS[cd] ‘Call’ AND visible == 1”));

el2.click();`

org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

in debug mode

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [January 4, 2022, 1:05pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/18 "2022-01-04T13:05:40Z")

</div>

all 3 examples?  
write after error happen get:

```auto
System.out.println(driver.getPageSource());

```

and write here pageSource at moment of fail.

---

<div class="post-metadata">

**Author:** ![I7210I](https://discuss.appium.io/letter_avatar_proxy/v4/letter/i/a698b9/32.png) [@I7210I](https://discuss.appium.io/u/I7210I)\
**Post date:** [January 4, 2022, 1:11pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/19 "2022-01-04T13:11:16Z")

</div>

I’m using the 3rd example since I don’t want to work on just “166”, and page source right away isn’t go since

`WebElement el2 = getDriver().findElement(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeButton' AND name CONTAINS[cd] 'Call' AND visible == 1"));`  
is failed the test

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [January 4, 2022, 1:12pm UTC](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332/20 "2022-01-04T13:12:56Z")

</div>

we will not understand until you get page source at moment of fail

[Next page](https://discuss.appium.io/t/click-on-element-in-alert-ios-15/35332.md?page=2)
