# PageFactory implementation for By/AppiumBy object types

**URL:** <https://discuss.appium.io/t/pagefactory-implementation-for-by-appiumby-object-types/39410>\
**Category:** Feature\
**Created:** [June 11, 2023, 3:06pm UTC](https://discuss.appium.io/t/pagefactory-implementation-for-by-appiumby-object-types/39410 "2023-06-11T15:06:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikola88](https://discuss.appium.io/user_avatar/discuss.appium.io/nikola88/32/9225_2.png) [@Nikola88](https://discuss.appium.io/u/Nikola88)\
**Post date:** [June 11, 2023, 3:06pm UTC](https://discuss.appium.io/t/pagefactory-implementation-for-by-appiumby-object-types/39410/1 "2023-06-11T15:06:02Z")

</div>

Hello! I recently encountered the following struggle:

I was re-building a cross-platform testing solution and was about to implement changes with PageFactory, as it’s a very efficient way to build tests fast and with less code for 2 platforms at the same time. What happened is that one of the internal SDK’s, used by the project in question, got updated to Java 17 and created a compatibility issue with PageFactory (the problem is that PageFactory uses cglib, which is not maintained nor updated for Java17).

After some thinking I went ahead and implemented a custom and very simplified implementation of a custom PageFactory, which works with By, instead of WebElement. The reasons I did it like that are:

1. Simplicity - this way the code is quite simplified, without having to instantiate the actual WebElements right away and thus no need for complicated proxying of the objects.
2. Flexibility - WebElements are great but they are not as flexible as the By locators, and also can be acquired at will as long as you have the By for the given element, but not the other way around.

This ended up being quite effective and I was wondering if this is something that may be of interest/demand? I can contribute my code if moderators agree this could be useful for many many people, I just want to know if this is something that the Appium community may be interested in. It’s purpose will not only be a (more stable) alternative for PageFactory, but also maybe a successor for it, unless the Selenium community updates that part of Selenium to not depend on cglib.

---

<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:** [June 11, 2023, 3:34pm UTC](https://discuss.appium.io/t/pagefactory-implementation-for-by-appiumby-object-types/39410/2 "2023-06-11T15:34:24Z")

</div>

Seems like a good idea, you should check with the folks at:

> **[GitHub - appium/java-client: Java language binding for writing Appium Tests,...](https://github.com/appium/java-client)**
>
> Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol - GitHub - appium/java-client: Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol

---

<div class="post-metadata">

**Author:** ![Nikola88](https://discuss.appium.io/user_avatar/discuss.appium.io/nikola88/32/9225_2.png) [@Nikola88](https://discuss.appium.io/u/Nikola88)\
**Post date:** [June 11, 2023, 4:18pm UTC](https://discuss.appium.io/t/pagefactory-implementation-for-by-appiumby-object-types/39410/3 "2023-06-11T16:18:55Z")

</div>

Great, will do. Thanks!

---

<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:** [June 11, 2023, 8:00pm UTC](https://discuss.appium.io/t/pagefactory-implementation-for-by-appiumby-object-types/39410/4 "2023-06-11T20:00:35Z")

</div>

> [@Nikola88](#):
>
> the problem is that PageFactory uses cglib, which is not maintained nor updated for Java17

> **[Solving the JDK 17 Compatibility Issue with Appium: A Step-by-Step Guide](https://www.linkedin.com/pulse/solving-jdk-17-compatibility-issue-appium-step-by-step-nir-tal/)**
>
> Introduction Mobile automation is the process of automating the testing of mobile applications. It helps to ensure that an app functions as intended and meets the desired quality standards before it is released to the public.

---

<div class="post-metadata">

**Author:** ![Nikola88](https://discuss.appium.io/user_avatar/discuss.appium.io/nikola88/32/9225_2.png) [@Nikola88](https://discuss.appium.io/u/Nikola88)\
**Post date:** [July 20, 2023, 2:54pm UTC](https://discuss.appium.io/t/pagefactory-implementation-for-by-appiumby-object-types/39410/5 "2023-07-20T14:54:06Z")

</div>

I know, I also saw that they replaced cglib with bytebuddy, which solved the issue. However this implementation, so far from my experience, works very smooth and even faster than the current PageFactory (as it is quite simpler, it doesn’t need to use reflection and proxying at all). I opened an issue in the Java client repo asking if there is interest, but I got no response.
