How to get text of highlighted element

i have used id and xpath it is not working

tried ?

driver.findElement(MobileBy.id(“balanceAmt”)).getText();

no it is not working it says no such element found

getText() should work for above element because its textview. You can try getAttribute or getText()
> WebElement balanceAmount = driver.findElement(By.id(“balanceAmt”));

System.out.println("Balance : " + balanceAmount.getAttribute("text"));
System.out.println("Balance : " + balanceAmount.getText());

no it is not working i have tried that also

package com.finwizard.fisdom;

import org.testng.annotations.Test;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

public class LoginFisdom {

private AndroidDriver<AndroidElement>driver;

@BeforeTest
public void setUp() throws Exception {

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName","ZY222XVS7H");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("appPackage", "com.finwizard.fisdom");
capabilities.setCapability("appActivity", "com.finwizard.fisdom.landing.LandingPageActivity");
driver =new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

}

@Test
public void testLogin(){

driver.findElementById(“com.finwizard.fisdom:id/signin”).click();
driver.findElementById(“com.finwizard.fisdom:id/email”).sendKeys("[email protected]");
driver.hideKeyboard();
driver.findElementById(“com.finwizard.fisdom:id/password”).sendKeys(“domore”);
driver.hideKeyboard();
driver.findElementById(“com.finwizard.fisdom:id/signin”).click();
//AndroidElement text = driver.findElementByXPath("//android.widget.RelativeLayout[@resource-id=‘com.finwizard.fisdom:id/balanceAmt’]");
//System.out.println(text.getText());
/*System.out.println("Balance: " + balance.getText());
AndroidElement earnings = driver.findElementById(“com.finwizard.fisdom:id/earningsAmt”);
System.out.println( "Earnings: " + earnings.getText());
*/
//List text= driver.findElementsByClassName(“android.widget.TextView”);
//AndroidElement element = text.get(1);
System.out.println(driver.findElement(MobileBy.id(“com.finwizard.fisdom:id/balanceAmt”)).getText());

}

@AfterTest

public void tearDown() throws Exception {
driver.quit();
}

}

The xpath you have used -

AndroidElement text = driver.findElementByXPath(“//android.widget.RelativeLayout[@resource-id=‘com.finwizard.fisdom:id/balanceAmt’]”);

This is incorrect because its TextView not RelativeLayout. Also, because there is page or view transition between sign in and checking balance so I would suggest to add a wait statement before checking balance amount.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(BY-LOCATOR-STRATEGY-HERE));

if i use wait can i find the element by id

yeah, just wait for the balance page to load.

you do not need to use full id with package name. it is enough to use just

balanceAmt

Thankyou suman and Aleksei now it is working

Thankyou for ur time