MobileElement Cannot instantiate

Hi,

I cloned the sample test project form the below link

Once i updated the java_client dependency to 2.1.0 i get error on MobileElement.
/**
* Wrap WebElement in MobileElement *
*/
private static MobileElement w(WebElement element) {
return new MobileElement((RemoteWebElement) element, driver);
}

Cannot instantiate the type MobileElement(io.appium.java_client.MobileElement is abstract; cannot be instantiated), is the error i’m getting

How can i get this fixed.

Regards,
Sai

This sample is outdated. MobileElement is abstract since 2.0.0. It has no constructor like

new MobileElement((RemoteWebElement) element, driver)

Here only default constructor without any parameter. Also… It is important to know… You can instantiate mobile element that way

MobileElement e = yourAndroidDriver.findElement(By) //yourIOSDriver.findElement(By)

I advice you to look at GitHub - appium-boneyard/java-workshop: Java workshop for Appium

@SergeyTichomirov how can I change the above method ? So that I can continue keeping the framework as it is …

Are you talking about

?

So you don’t need something special to do. If you work with AndroidDriver/IOSDriver then parameter

WebElement element

is already MobileElement. You can remove and forget about the method above. :smile:

Am I understand you correctly?

Perfect thanks a lot… Will give it a try :smile:

Using MobileElement can I still access the click() or should I use tap()

Click is more universal action. tap, swipe, zoom work cool with native content now. They are supposed to be available in webview/browser when it will be merged and published:

mobileelement did not work for me,…unneccsarly i wasted 3 hrs on this, by using it the typing in the textbox is not happening.

/**

  • Wrap WebElement in MobileElement *
    */
    private static MobileElement w(WebElement element) {
    return (MobileElement) element;
    }