Getting Class cast exception for xpath to AppiumBy

Hi All,

I am getting below error–

java.lang.ClassCastException: class org.openqa.selenium.By$ByXPath cannot be cast to class io.appium.java_client.AppiumBy (org.openqa.selenium.By$ByXPath and io.appium.java_client.AppiumBy are in unnamed module of loader 'app')

I am currently using A
Appium v2.0.1
Java client 8.5.1

Getting error at this line in my page class:
private AppiumBy STANDARD_USER= (AppiumBy) AppiumBy.xpath ("some xpath");

Getting no logs at Appium as it fails in the initialization step only.

Can’t do this.

Yeah, it’s just a mistake in your coding. Probably gets caught before Appium even gets started. Good read here:

This is not correct. Xpath is part of By method which AppiumBy extends.

private By STANDARD_USER = AppiumBy.xpath ("some xpath");

Thanks @Aleksei for the correct way shown.

I observed that it was an issue with Eclipse IDE but not with Intellij Idea.

I just used private AppiumBy STANDARD_USER= (AppiumBy) AppiumBy.xpath (“some xpath”); as experiment after your reply and found it is not giving me ClassCastException in Intellij Idea IDE.

I will use the correct way nevertheless.