“Click Element At Coordinates” & “Long Press” Keywords are not working with Selenium 4.0+ and Appium 2.0+ in Mobile Automation for Android & iOS
Setup:
selenium: 4.10.0
robotframework: 6.0.2
robotframework-appiumlibrary: 2.0.0
“Click Element At Coordinates” & “Long Press” Keywords are not working with Selenium 4.0+ and Appium 2.0+ in Mobile Automation for Android & iOS
Setup:
selenium: 4.10.0
robotframework: 6.0.2
robotframework-appiumlibrary: 2.0.0
Are there any specific error messages that the script produces (possibly run under TRACE log level)?
There is a known issue with SeleniumLibrary and Selenium 4.10.0 such that at this time it is recommended to downgrade to Selenium 4.9.1 (one can do this with the command pip install selenium==4.9.1
). I don’t know how the Appium stack ties into/through SeleniumLibrary but ieven if not it may still have the same issue with Selenium 4.10.0.
Thank you @EdManlove for the reply
Here are the console logs and Stacktrace for reference:
[ WARN ] Keyword ‘AppiumLibrary.Click Element At Coordinates’ is deprecated. Since selenium v4, use other keywords.
WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: this[mobileCommandsMapping[mobileCommand]] is not a function
Stacktrace:
UnknownError: An unknown server-side error occurred while processing the command. Original error: this[mobileCommandsMapping[mobileCommand]] is not a function
at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/errors.js:1067:9)
at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/@appium/base-driver/lib/protocol/protocol.js:491:57)
After downgrading from Selenium 4.10.0 to 4.9.1, “Click Element At Coordinates” keyword is working, however it is still showing deprecation error; which doesn’t look good on the console. and for long-term plan however it will stop working. So for each and every deprecated keyword in Selenium/Appium there should be alternatives available readily. So users can easily migrate instead of searching over and there !!
“Hide Keyboard” is also not working !! Instead I am using “Go Back” which will hide the keyboard
Tap With Positions should be working alternative: http://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html#Tap%20With%20Positions
For the Hide Keyboard, are you testing against iOS or Android? For iOS you may need to define how to close the keyboard: http://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html#Hide%20Keyboard
Also, with the Execute Script -keyword you should be able to execute OS specific gestures, for example with Android, see: https://github.com/appium/appium-uiautomator2-driver/blob/master/docs/android-mobile-gestures.md
Tap with Positions doesn’t work !!!
I tried by giving x y coordinates as a list to the argument of “Tap with Positions” but it didn’t work. Initially it gave me data type related error, So I converted x y coordinates to str type, after that keyword executes successful, but didn’t function at all.
For Hide keyword, I am using this for Android & iOS both, For iOS till now I didn’t have to give any extra arguments. But there is no issue I can replace Hide Keyboard with Go Back.
Thanks
Ok thanks,
Can you give me alternative mobile: cmd for “Click Element At Coordinates”, “Hide Keyboard”, and “Long Press”; if possible ? It would be very helpful. and if you know what will be format/syntax for “execute script” in Robot Framework would also help me.
Thanks in advance.
If possible I want generic solution/workaround for Android & iOS. As I am using both and till now it was generic !!!
There should be some data regarding, Why Selenium need to deprecate the touchActions in Appium and if it deprecated then what is alternative generic solution which will work for Android & iOS in the same manner/solution
I don’t have any issues with Tap With Coordinates. Did you notice that it takes list of lists?
@{first_coordinates} Create List ${590} ${2140}
@{all_coordinates} Create List ${first_coordinates}
Tap With Positions ${1000} @{all_coordinates}
For Long Press I have created a new keyword with Python, but there is no reason why something similar could not be done with the Robot syntax also.
@keyword("Long Click Element")
def long_click_element(self, locator, duration=2000):
"""Executes long press gesture the specified element
| =Arguments= | =Description= |
| locator | locator for the element |
| duration | duration of the press in ms |
"""
os = BuiltIn().get_variable_value('${OPERATING_SYSTEM}')
appiumlib = BuiltIn().get_library_instance('AppiumLibrary')
driver = self._get_driver_instance()
element = appiumlib._element_find(locator, True, True)
logger.info(f"Long clicking element {locator} ({element.id}) for {duration} ms")
if os == "android":
driver.execute_script('mobile: longClickGesture', {'elementId': element.id, 'duration': duration})
else:
driver.execute_script('mobile: touchAndHold', {'element': element.id, 'duration': duration / 1000})
But yes, I do agree that the Selenium 4.10 release was kinda nasty, because there was no way to know that the deprecated things are going to be removed in that version, as they are not following semantic versioning.
For touchActions there should be w3c_actions as a replacement, but I have never tried those: Reddit - Dive into anything
Ok thanks buddy !
@jasal
I am using this in my framework.
Custom Long Press
[Arguments] ${locator} ${duration}=2000
wait until element is visible ${locator}
${element_location} get element rect ${locator}
${x} evaluate ${element_location}+(${element_location}[width]//2)
${y} evaluate ${element_location}[y]+(${element_location}[height]//2)
${tap_positions} create list ${x} ${y}
log list ${tap_positions}
Tap With Positions ${duration} ${tap_positions}
Thank you for the reply, However, It is not working for me !!!