# Element Locators with different environment

**URL:** <https://discuss.appium.io/t/element-locators-with-different-environment/34627>\
**Category:** Support\
**Created:** [September 23, 2021, 1:44pm UTC](https://discuss.appium.io/t/element-locators-with-different-environment/34627 "2021-09-23T13:44:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarek](https://discuss.appium.io/letter_avatar_proxy/v4/letter/t/cdc98d/32.png) [@Tarek](https://discuss.appium.io/u/Tarek)\
**Post date:** [September 23, 2021, 1:44pm UTC](https://discuss.appium.io/t/element-locators-with-different-environment/34627/1 "2021-09-23T13:44:22Z")

</div>

Hi,

We are implementing an appium automation that should be ran on different environments having the same app/code. I am using @AndroidFindBy and pageFactory to locate my elements in Android. Now with the new issue we’re facing, the ID of an element will change with respect to the environment we are testing on: for example, in the staging environment the element’s ID will be similar to: “com.app.staging:firstName” while in the second environment, the element’s ID will be similar to “com.app.developer:firstName”. How can I achieve such dynamic implementation of element locators?

@AndroidFindBy does not support dynamic strings in the find by expression. Please feel free to share any idea regarding this topic under this post.

Thank you!

---

<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:** [September 23, 2021, 3:49pm UTC](https://discuss.appium.io/t/element-locators-with-different-environment/34627/2 "2021-09-23T15:49:24Z")

</div>

If change only in app package name then do not worry. Just set id without package name. Appium will add it.

---

<div class="post-metadata">

**Author:** ![Tarek](https://discuss.appium.io/letter_avatar_proxy/v4/letter/t/cdc98d/32.png) [@Tarek](https://discuss.appium.io/u/Tarek)\
**Post date:** [September 23, 2021, 4:49pm UTC](https://discuss.appium.io/t/element-locators-with-different-environment/34627/3 "2021-09-23T16:49:02Z")

</div>

Thank you @Aleksei , I did not think about such approach. What I have implemented for now is:

```
@AndroidFindBy(xpath = "//*[ends-with(@resource-id, 'id/firstName')]")

```

Do you recommend that I switch back to your answer, or are both fine to implement

---

<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:** [September 23, 2021, 6:04pm UTC](https://discuss.appium.io/t/element-locators-with-different-environment/34627/4 "2021-09-23T18:04:09Z")

</div>

```auto
@AndroidFindBy(id = "firstName")

```

is better way
