I have a problem extracting text from a label and displaying it by console

-1

I am trying to automate an app which I need to read a label and its text, and that this is shown by console the app is as follows.

DesiredCapabilities dc = new DesiredCapabilities();
    //@BeforeMethod
    protected void setUp(String deviceName, String versionAndroid ) throws MalformedURLException {
      dc.setCapability("deviceName", deviceName);
      dc.setCapability("platformVersion", versionAndroid);
      dc.setCapability("platformName","Android");
      dc.setCapability("automationName","Appium");
      dc.setCapability("appPackage", "com.ripley.banco.peru");
        dc.setCapability("appActivity", "md50120b660b57d6504f7403c716c787885.MainActivity");
        //driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), dc);
        driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), dc);
        driver.setLogLevel(Level.INFO);
    }

this is the method:

protected void prueba(String equipo,String versionSO) throws MalformedURLException {
        setUp(equipo, versionSO);
        waitSleep(2);
        //if(assertEquals(driver.findElement(Constantes.txtTipoDeDocumento)) == "Tipo de documento"){
        AndroidElement ele = (AndroidElement) driver.findElement(By.xpath(Constantes.txtTipoDeDocumento));
        //(RemoteElement)driver.findElement(By.xpath(Constantes.txtTipoDeDocumento));
        System.out.println(ele.getText());

            }

at the end, he throws this error at me.

  

java.lang.ClassCastException:   org.openqa.selenium.remote.RemoteWebElement can not be cast   io.appium.java_client.android.AndroidElement at   pe.abs.absRipley.test (absRipley.java:827) at   pe.casos.TestEscenario1.caso46 (TestEscenario1.java:39) at   sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at   sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source) at   sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown Source) at   java.lang.reflect.Method.invoke (Unknown Source) at   org.testng.internal.MethodInvocationHelper.invokeMethod (MethodInvocationHelper.java:108)     at org.testng.internal.Invoker.invokeMethod (Invoker.java:661) at   org.testng.internal.Invoker.invokeTestMethod (Invoker.java:869) at   org.testng.internal.Invoker.invokeTestMethods (Invoker.java:1193) at   org.testng.internal.TestMethodWorker.invokeTestMethods (TestMethodWorker.java:126)     at   org.testng.internal.TestMethodWorker.run (TestMethodWorker.java:109)     at org.testng.TestRunner.privateRun (TestRunner.java:744) at   org.testng.TestRunner.run (TestRunner.java:602) at   org.testng.SuiteRunner.runTest (SuiteRunner.java:380) at   org.testng.SuiteRunner.runSequentially (SuiteRunner.java:375) at   org.testng.SuiteRunner.privateRun (SuiteRunner.java:340) at   org.testng.SuiteRunner.run (SuiteRunner.java:289) at   org.testng.SuiteRunnerWorker.runSuite (SuiteRunnerWorker.java:52) at   org.testng.SuiteRunnerWorker.run (SuiteRunnerWorker.java:86) at   org.testng.TestNG.runSuitesSequentially (TestNG.java:1301) at   org.testng.TestNG.runSuitesLocally (TestNG.java:1226) at   org.testng.TestNG.runSuites (TestNG.java:1144) at   org.testng.TestNG.run (TestNG.java:1115) at   org.testng.remote.AbstractRemoteTestNG.run (AbstractRemoteTestNG.java:114)     at org.testng.remote.RemoteTestNG.initAndRun (RemoteTestNG.java:251)     at org.testng.remote.RemoteTestNG.main (RemoteTestNG.java:77)

     

=================================================================================================       Default test       Tests run: 1, Failures: 1, Skips: 0

    
asked by Christian Andres Hyuden 01.09.2018 в 01:56
source

2 answers

0

You must convert the text you get to string:

Change this line:

System.out.println(ele.getText());

For this:

System.out.println(ele.getText().toString);
    
answered by 01.09.2018 в 05:47
0

I already solved it I did it in the following way:

RemoteWebElement ele = (RemoteWebElement) driver.findElement (By.xpath (Constants.txtTypeofDocument));

System.out.prinln (ele.getString ());

    
answered by 03.09.2018 в 18:52