-
Notifications
You must be signed in to change notification settings - Fork 568
Closed
Labels
Description
The problem
We have a general drag_and_drop() implemented in ActionHelpers class, which is accessible via driver object driver.drag_and_drop(origin_el, destination_el)
.This is not working in many cases we need to hold more than default to make element draggable. For example in appium official ApiDemos app > Views > Drag and Drop, it is not working.
To reproduce:
(ApiDemos should be installed and appium server running)
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.action_chains import ActionChains
desired_caps= {
"appium:appPackage": "io.appium.android.apis",
"appium:appActivity": ".ApiDemos",
"platformName": "Android",
"appium:automationName": "UiAutomator2"
}
appium_server = "http://127.0.0.1:4723"
appium_options = UiAutomator2Options().load_capabilities(desired_caps)
driver = webdriver.Remote(appium_server, options=appium_options)
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Views').click()
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Drag and Drop').click()
el1 = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_dot_1')
el2 = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_dot_2')
el3 = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_dot_3')
driver.drag_and_drop(el1, el2) # it is not working
result = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_result_text').get_attribute('text')
assert 'Dropped!' in result
So if I add a simple pause for 1 sec in implementation, it will works. Following is working code which I used the same implementation of ActionHelpers but I added a pause there:
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from appium.options.android import UiAutomator2Options
from selenium.webdriver.common.action_chains import ActionChains
desired_caps= {
"appium:appPackage": "io.appium.android.apis",
"appium:appActivity": ".ApiDemos",
"platformName": "Android",
"appium:automationName": "UiAutomator2"
}
appium_server = "http://127.0.0.1:4723"
appium_options = UiAutomator2Options().load_capabilities(desired_caps)
driver = webdriver.Remote(appium_server, options=appium_options)
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Views').click()
driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='Drag and Drop').click()
el1 = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_dot_1')
el2 = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_dot_2')
el3 = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_dot_3')
# Now it is working
actions = ActionChains(driver)
actions.w3c_actions.pointer_action.click_and_hold(el1)
actions.w3c_actions.pointer_action.pause(1) # by adding this
actions.w3c_actions.pointer_action.move_to(el2)
actions.w3c_actions.pointer_action.release()
actions.perform()
# driver.drag_and_drop(el1, el2)
result = driver.find_element(by=AppiumBy.ID, value='io.appium.android.apis:id/drag_result_text').get_attribute('text')
assert 'Dropped!' in result
Environment
- Appium version (or git revision) that exhibits the issue: v2.4.1
- Last Appium version that did not exhibit the issue (if applicable): Latest
- Desktop OS/version used to run Appium: Windows 11
- Node.js version (unless using Appium.app|exe): v20.10.0
- Mobile platform/version under test: Android 11 / Google Pixel 4
- Real device or emulator/simulator: Emulator (AVD)
- Appium CLI or Appium.app|exe: CLI
Log for failing code: Gist
Log for passing code: Gist
I'm willing to contribute if code owners confirm.