Problem with clicking on the element

Hello.
I already configured Appium and tried to run the first test but I encountered a problem with clicking on the element. The console gives me a statement

Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“id”,“selector”:“Located by By.chained({By.id: search_query_top})”}

This is the code I execute

public class LoginPage {

private AppiumDriver<?> driver;

public LoginPage(AppiumDriver<?> driver) {
    this.driver = driver;
    PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(10)), this);
}

@AndroidFindBy(id = "search_query_top") public AndroidElement searchInput;
@AndroidFindBy(id = "password") public AndroidElement passwordInput;
@AndroidFindBy(id = "login-button") public AndroidElement loginButton;

public void waitUntilVisible(MobileElement androidElement) {
    new WebDriverWait(driver, 15)
            .until(ExpectedConditions.visibilityOfElementLocated(By.id(androidElement.toString())));
}

public void fillUsernameInput(String username) {
    waitUntilVisible(searchInput);
    searchInput.click();
    searchInput.sendKeys(username);
}

but console return something like this

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/home/maryna/.m2/repository/cglib/cglib/3.2.12/cglib-3.2.12.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.id: Located by By.chained({By.id: search_query_top}) (tried for 15 second(s) with 500 milliseconds interval)

	at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:95)
	at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:272)
	at pages.LoginPage.waitUntilVisible(LoginPage.java:35)
	at pages.LoginPage.fillUsernameInput(LoginPage.java:39)
	at tests.LoginTests.loginAsStandardUserAndVerifyIfLoggedIn(LoginTests.java:32)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:599)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:174)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:822)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:147)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1540)
	at org.testng.TestRunner.privateRun(TestRunner.java:764)
	at org.testng.TestRunner.run(TestRunner.java:585)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:384)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:378)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:337)
	at org.testng.SuiteRunner.run(SuiteRunner.java:286)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1218)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
	at org.testng.TestNG.runSuites(TestNG.java:1069)
	at org.testng.TestNG.run(TestNG.java:1037)
	at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
	at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:110)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"Located by By.chained({By.id: search_query_top})"}
  (Session info: chrome=92.0.4515.166)
  (Driver info: chromedriver=91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch-heads/4472@{#1462}),platform=Linux 5.4.0-72-generic x86_64)
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:17:03'
System info: host: 'maryna', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.0-72-generic', java.version: '11.0.6'
Driver info: io.appium.java_client.AppiumDriver
Capabilities {appActivity: com.google.android.apps.chr..., appPackage: com.android.chrome, automationName: UiAutomator2, browserName: Chrome, chromeOptions: {w3c: false}, chromedriverExecutable: /home/maryna/drivers/chrome..., databaseEnabled: false, desired: {automationName: UiAutomator2, browserName: Chrome, chromeOptions: {w3c: false}, chromedriverExecutable: /home/maryna/drivers/chrome..., deviceName: Xiaomi Mi A2, noReset: true, platformName: android, platformVersion: 10}, deviceApiLevel: 29, deviceManufacturer: Xiaomi, deviceModel: Mi A2, deviceName: 233cc482, deviceScreenDensity: 408, deviceScreenSize: 1080x2160, deviceUDID: 233cc482, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: true, pixelRatio: 2.55, platform: LINUX, platformName: Android, platformVersion: 10, statBarHeight: 61, takesScreenshot: true, viewportRect: {height: 1977, left: 0, top: 61, width: 1080}, warnings: {}, webStorageEnabled: false}
Session ID: 71d0cb60-f387-4a2b-8183-73610defd508
*** Element info: {Using=id, value=Located by By.chained({By.id: search_query_top})}
	at jdk.internal.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	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 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 org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)
	at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:69)
	at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)
	at org.openqa.selenium.By$ById.findElement(By.java:188)
	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 org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:205)
	at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:201)
	at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:249)
	... 30 more

What is wrong with this test? Thanks in advance

in logs we see element with id ‘search_query_top’ NOT found. share us your page source.

BTW in most cases your code should be just like:

searchInput.sendKeys(username);

other lines:

    waitUntilVisible(searchInput);
    searchInput.click();

not needed! in most cases.

@Aleksei Thanks for the reply. I used http://automationpractice.com/ website and there we can find element with id = “search_query_top”

it will help to see how Appium sees it.

This is how it looks like

try add capability:
autoWebview = true -> https://appium.io/docs/en/writing-running-appium/caps/

but in general it looks incorrect. you should start appium driver for chrome and execute tests like in pure web.

also! it is 100% better execute tests in chrome on PC/MAC using mobile emulations. it is 100 times faster. and only some critical tests execute on real phone device.