I am unable to perform any operations in appium

Unable to compile '//android.widget.Button[text=‘Use a different account for this app]’. See Cause.
written the xpath but not ableto compile the code.

write whole line of code. correct code something like:

MobileElement el = (MobileElement) driver.findElement(MobileBy.xpath("//android.widget.Button[text='Use a different account for this app']"));

Hi,
please check this code,if there is something wrong let me know.

package sampleandroid.com;

import java.net.MalformedURLException;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

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

public class amazon2 extends android1
{

public static void main(String[] args) throws MalformedURLException, InterruptedException 
{
	AndroidDriver<AndroidElement> driver=setupDesiredCapabilities();
     driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);
     Thread.sleep(25000);
    
     MobileElement el = (MobileElement) driver.findElement(MobileBy.xpath("//android.widget.Button[text='Use a different account for this app']"));
     el.click();
}

}

still no click operation is performed.please help out.
I am not able to click,sendkeys operation in any of the apps,i m testing,just struck in the initial stage.

Throws the error:
An element could not be located on the page using the given search parameters.

This means your search pattern not correct. Give us output of driver.getPageSource() to help

inspect element is done by UI automator/appium desktop.
Please help me out

error:
Nov 05, 2020 11:50:07 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread “main” org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:48’
System info: host: ‘GVG72’, ip: ‘192.168.43.96’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_181’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: D:\Seleniumworkspace\sample…, appPackage: com.amazon.venezia, automationName: uiautomator2, databaseEnabled: false, desired: {app: D:\Seleniumworkspace\sample…, automationName: uiautomator2, deviceName: sampleemulator, platformName: android}, deviceApiLevel: 29, deviceManufacturer: samsung, deviceModel: SM-A205F, deviceName: RZ8M40SHMCX, deviceScreenDensity: 280, deviceScreenSize: 720x1560, deviceUDID: RZ8M40SHMCX, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, pixelRatio: 1.75, platform: LINUX, platformName: Android, platformVersion: 10, statBarHeight: 53, takesScreenshot: true, viewportRect: {height: 1370, left: 0, top: 53, width: 720}, warnings: {}, webStorageEnabled: false}
Session ID: 9759a927-b129-40f1-bb71-ef214cf456b4
*** Element info: {Using=xpath, value=//android.widget.Button[@text=‘Use a different account for this app’]}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)
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.findElementByXPath(RemoteWebDriver.java:428)
at io.appium.java_client.DefaultGenericMobileDriver.findElementByXPath(DefaultGenericMobileDriver.java:151)
at io.appium.java_client.AppiumDriver.findElementByXPath(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElementByXPath(AndroidDriver.java:1)
at org.openqa.selenium.By$ByXPath.findElement(By.java:353)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:315)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:57)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at sampleandroid.com.amazon2.main(amazon2.java:22)

try UISelector instead:

MobileElement el = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().textContains(\"Use a different account\")"));

not working.
Tel us some app so that i can checkin that.like actions are performed or not

https://github.com/appium/java-client/tree/master/src/test/resources/apps -> ApiDemos-debug.apk

In these app,we get some error as not supported for Android 10.
If i write the script to click on “OK” button it is not performed.
These step i have struck in these app.

code:
package sampleandroid.com;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class test1 {

public static AndroidDriver<AndroidElement> setupDesiredCapabilities() throws MalformedURLException {
	
	// 1 Create File class to point to the tested application "ApiDemons-debug.apk"
	File src		= new File("src");
	File app 		= new File(src, "ApiDemos-debug.apk");		
	
	// 2 Create DesiredCapabilities object called 'cap'
	DesiredCapabilities capabilities = new DesiredCapabilities();
	
	// 2.1 Set device name, application path, emulator name as our desired capabilities.
	capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
	capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
	capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
	
	capabilities.setCapability("autoGrantPermissions", true);
     capabilities.setCapability("noReset", "false");
     capabilities.setCapability("fullReset", "true");
	
	// 2.2 Create an object of URL class
	URL url = new URL("http://127.0.0.1:4723/wd/hub");		
		
	/*
	 * 3 Create an Android Driver with specifying 2 arguments:
	 * 		- URL to Appium server
	 * 		- Desired Capabilities
	 */
	AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(url, capabilities);

	 driver.findElement(By.xpath(("//android.widget.Button[@text='OK']"))).click();
	return driver;
}


	// TODO Auto-generated method stub

}

hi sir,
i am able to perform now,added one coomon.lang jar file.

thanks for the support

which appium client lib are flexible to use.
I use 7.3 where some of library methods are not obtained like scrollable,withelement


Please help me out which to use

it is pure android uiselector command. commands taken from here -> https://developer.android.com/reference/androidx/test/uiautomator/UiSelector