Reputation: 14418
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'
Upvotes: 0
Views: 27
Reputation: 1289
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)
Upvotes: 0