admin管理员组

文章数量:1308024

I am trying to automate some flow in UIAutomator and a part of it has been to press the copy button on an app, after pressing this copy button I would need to access the copied content in code via python UIAutomator... how do I do so?

COPY_KEY = {
    CLASS_NAME: "android.widget.Button",
    DESCRIPTION: "Copy key"
}
self.DEVICE.get_element(self.COPY_KEY).click()
clean_seed = 'copied code'

I am trying to automate some flow in UIAutomator and a part of it has been to press the copy button on an app, after pressing this copy button I would need to access the copied content in code via python UIAutomator... how do I do so?

COPY_KEY = {
    CLASS_NAME: "android.widget.Button",
    DESCRIPTION: "Copy key"
}
self.DEVICE.get_element(self.COPY_KEY).click()
clean_seed = 'copied code'
Share Improve this question edited Feb 3 at 16:33 globglogabgalab 4493 silver badges14 bronze badges asked Feb 2 at 7:24 aherlambangaherlambang 14.4k54 gold badges153 silver badges255 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Accessing copied text via Python UIAutomator2 typically boils down to reading system clipboard on Android device after you have triggered the Copy action.Currently UIAutomator2 does not provide built-in get clipboard method in all versions so most reliable approach is to use an ADB shell command via the `device.shell(...) interface

You can use am get-clipboard (Android 10+)

import uiautomator2 as u2

d = u2.connect()
d(resourceId="com.example:id/my_copy_button").click()
copied_text = d.shell("am get-clipboard").strip()
print("Copied text:", copied_text)

本文标签: how to access copied content in python UIAutomator2Stack Overflow