最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to access copied content in python UIAutomator2 - Stack Overflow

programmeradmin0浏览0评论

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)
发布评论

评论列表(0)

  1. 暂无评论