AndroidDriver tap() method throwing exception "com.sun.proxy.$Proxy22 cannot be cast to org.openqa.selenium.remote.RemoteWebElement"


I am using PageObjectModel/PageFactory for my tests on an android native app.
Everything is working fine except the tap() method. Java throws “com.sun.proxy.$Proxy22 cannot be cast to org.openqa.selenium.remote.RemoteWebElement” exception when trying to execute this method.

Below is some part of the code:

AndroidDriver driver = new AndroidDriver(new URL("…"), capabilities);

@FindBy(xpath = “//android.widget.TextView[@text=‘Message’]”)
public WebElement messageAppOnTile;

PageFactory.initElements(driver, pageObject);

driver.tap(1, pageObject.messageAppOnTile, 500);

Java throws this exception when trying to execute the above line - “com.sun.proxy.$Proxy22 cannot be cast to org.openqa.selenium.remote.RemoteWebElement”

And tap() worked fine when I tried driver.tap(1, driver.findElement(By.xpath("//android.widget.TextView[@text=‘Message’]")), 500);

Selenium - 2.53.0
Appium Java Client - 3.4.1
Appium Server -

Why tap is not working when WebElements are initialised using PageFactory.initElements()?
Has anyone seen this issue before?


change this:
PageFactory.initElements(driver, pageObject);

to this:
PageFactory.initElements(new AppiumFieldDecorator(driver), this);

1 Like

Made this change and it works fine now. Thanks. :+1:

Hi @william why this is happening if we PageFactory.initElements(driver, pageObject);

Worked for me too! Thanks. :slight_smile:

I am also using PageObjectModel/PageFactory for my tests on an android native app. But not able to run below TouchAction:

public MobilePageObject(final WebDriver driver) {

    super(driver, new Predicate<PageObject>() {
    	public boolean apply(PageObject page) {

                    .initElements(new AppiumFieldDecorator(((WebDriverFacade) page.getDriver()).getProxiedDriver(),
                            page.getImplicitWaitTimeout().in(TimeUnit.SECONDS), TimeUnit.SECONDS), page);
            return true;



public TouchAction scrolltoelement( ) {
WebDriver facade = getDriver();
WebDriver driver = ((WebDriverFacade)facade).getProxiedDriver();
TouchAction actions = new TouchAction((MobileDriver)driver) ;
return actions;

@AndroidFindBy(xpath="//android.widget.TextView[@text=‘NPO 2’]")
private WebElement scrollFrom;
@AndroidFindBy(xpath="//android.widget.TextView[@text=‘Comedy Central’]")
private WebElement scrollTo;


After running the code I am getting below error:
java.lang.ClassCastException: com.sun.proxy.$Proxy26 cannot be cast to org.openqa.selenium.remote.RemoteWebElement

Could you please help me with this

Thanks, it works for me.
My exception

java.lang.ClassCastException: com.sun.proxy.$Proxy19 cannot be cast to org.openqa.selenium.internal.HasIdentity

But can you define it as a story, about, what is the problem and how this AppiumFieldDecorator resolve the problem.