问题
try to find a solution for this topic and none of the answers all the websites won't help me,
Search keyboard Appium Java not function
example not helping codes:
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));
same with:
driver.sendKeyEvent(AndroidKeyCode.ENTER);
or:
((AndroidDriver)driver).pressKeyCode(66)
or:
((AndroidDriver)driver).pressKeyCode(84)
I'm using this appium version:
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>
</dependency>
the option do it via coordinates not workaround for me since this tests done with a real mobiles and any mobile with a different screen size resolution
Sharing the exception and stack trace
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: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'Haims-MacBook', ip: 'fe80:0:0:0:8ea:4c20:85c7:1988%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_112'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: net.XXX.XXX.ui.acti..., appPackage: net.XXX.XXX.qa, databaseEnabled: false, desired: {appActivity: net.XXX.XXX.ui.acti..., appPackage: net.XXX.XXX.qa, deviceName: Galaxy A20, noReset: false, platformName: android, platformVersion: 9}, deviceManufacturer: samsung, deviceModel: SM-A205FN, deviceName: R58M50DVABW, deviceScreenSize: 720x1560, deviceUDID: R58M50DVABW, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, noReset: false, platform: LINUX, platformName: Android, platformVersion: 9, takesScreenshot: true, warnings: {}, webStorageEnabled: false}
Session ID: ad88e2fa-102c-4e19-b8fa-ac48054838ff
回答1:
capabilities.setCapability("unicodeKeyboard", "true");
capabilities.setCapability("resetKeyboard", "true");
set this before trying
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.ENTER)
回答2:
You can use below code to press search button.
((JavascriptExecutor) driver).executeScript("mobile: performEditorAction", ImmutableMap.of("action", "search"));
If this doesn't work try replacing search with below commands
- go
- send
- next
- done
Also, if this doesn't work try giving 1 or 2 sec delay before the execution of this command. For more information you can refer http://appium.io/docs/en/commands/mobile-command/
来源:https://stackoverflow.com/questions/57872002/search-keyboard-appium-java-not-function