mercredi 21 août 2019

Unable to automate clicking of button in Mobile app

I am having trouble in simulating a click on a simple button (id = btn_sign_in) in a mobile app. I have tried a lot of combination using By.xpath, By.CLassname etc. but I keep getting error which is shown below.

First, here is my code.

public class Firstflow {
    static DesiredCapabilities dc = new DesiredCapabilities();
    @SuppressWarnings("rawtypes")
    static AndroidDriver driver;
    static AppiumDriver <MobileElement> driver_App;
    @SuppressWarnings("rawtypes")
    public static void main(String[] args) throws MalformedURLException, InterruptedException{              
        dc.setCapability("deviceName", "emulator-5444");
        dc.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.mol.molwallet.uat");
        //dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.mol.molwallet.module.start.UserGuidance.UserGuidanceActivity");
        //dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.mol.molwallet.module.login.SignPageActivity");
        System.out.println(dc);
        dc.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.mol.molwallet.module.start.SplashActivity");
        dc.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "60");
        dc.setCapability("noReset", "true");
        driver_App = new AndroidDriver<MobileElement>(new URL("http://localhost:4723/wd/hub"), dc);
        driver_App.setLogLevel(Level.INFO);
        Thread.sleep(5000); 
        String gps = driver_App.getPageSource();
        System.out.println(gps);
        //driver.findElement(By.xpath("//div/child::*[normalize-space()='SKIP']")).click();
        //driver.findElement(By.xpath("//android.widget.TextView[@text='SKIP']")).click();
        Thread.sleep(1000);
        //driver.findElement(By.xpath("//*[@text='LOG IN']")).click();
        //driver.findElement(By.xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.Button[2]")).click();
        driver_App.findElement(By.id("btn_sign_in")).click();
        driver_App.findElement(By.xpath("//*[@text='Region']")).click();
        driver_App.findElement(By.xpath("//*[@text='Malaysia']")).click();
        driver_App.findElement(By.xpath("//*[@id='etAccount']")).sendKeys("123456");
        driver_App.findElement(By.xpath("//*[@text='NEXT']")).click();
    }
}

The error message is as below:

INFO: Executed: [f0d477cf-ac78-426a-b2a8-9e08a3443e86, findElement {using=id, value=btn_sign_in}]
Exception in thread "main" org.openqa.selenium.WebDriverException: Returned value cannot be converted to WebElement: {element-6066-11e4-a52e-4f735466cecf=1, ELEMENT=1}
Build info: version: '2.53.0', revision: '35ae25b', time: '2016-03-15 16:57:40'
System info: host: 'RZB-MY-041', ip: '192.168.60.194', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: driver.version: AndroidDriver
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:370)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:413)
    at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:70)
    at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)
    at org.openqa.selenium.By$ById.findElement(By.java:218)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
    at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)
    at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
    at Firstflow.main(Firstflow.java:45)
Caused by: java.lang.ClassCastException: java.util.HashMap cannot be cast to org.openqa.selenium.WebElement
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:368)
    ... 13 more

I see two errors here:

a) Returned value cannot be converted to WebElement: {element-6066-11e4-a52e-4f735466cecf=1, ELEMENT=1}

b) java.util.HashMap cannot be cast to org.openqa.selenium.WebElement at org.openqa.selenium.remote.RemoteWebDriver.findElement

I am using Appium Server's element inspector to get the element's detail. Attached is the screenshot of the inpector's result.

enter image description here

I have try plenty findElement's syntax, and even change AndroidDriver to AppiumDriver, to no avail. I really hope it's nothing to do with any upgrading or downgrading of libraries. By the way, I am using Eclipse to write the automation test, so I do not have dependencies in Build.gradle or Maven. I just hope to have advice on what syntax should I use to click on the element. Thanks.

Aucun commentaire:

Enregistrer un commentaire