Skip to content

Commit af1988e

Browse files
authored
fix python3 set_clipboard error (#267)
* fix python3 set_clipboard error * apply formatter
1 parent 3a77054 commit af1988e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ from appium import webdriver
102102

103103
desired_caps = {}
104104
desired_caps['platformName'] = 'Android'
105-
desired_caps['platformVersion'] = '4.2'
105+
desired_caps['platformVersion'] = '8.1'
106+
desired_caps['automationName'] = 'uiautomator2'
106107
desired_caps['deviceName'] = 'Android Emulator'
107108
desired_caps['app'] = PATH('../../../apps/selendroid-test-app.apk')
108109

@@ -116,7 +117,8 @@ from appium import webdriver
116117

117118
desired_caps = {}
118119
desired_caps['platformName'] = 'iOS'
119-
desired_caps['platformVersion'] = '7.1'
120+
desired_caps['platformVersion'] = '11.4'
121+
desired_caps['automationName'] = 'xcuitest'
120122
desired_caps['deviceName'] = 'iPhone Simulator'
121123
desired_caps['app'] = PATH('../../apps/UICatalog.app.zip')
122124

appium/webdriver/webdriver.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ def set_clipboard(self, content, content_type=ClipboardContentType.PLAINTEXT, la
12711271
:param label: Optional label argument, which only works for Android
12721272
"""
12731273
options = {
1274-
'content': base64.b64encode(content),
1274+
'content': base64.b64encode(content).decode('UTF-8'),
12751275
'contentType': content_type,
12761276
}
12771277
if label:
@@ -1285,7 +1285,14 @@ def set_clipboard_text(self, text, label=None):
12851285
:param text: The text to be set
12861286
:param label: Optional label argument, which only works for Android
12871287
"""
1288-
self.set_clipboard(bytes(text.encode('UTF-8')), ClipboardContentType.PLAINTEXT, label)
1288+
1289+
def _bytes(value, encoding):
1290+
try:
1291+
return bytes(value, encoding) # Python 3
1292+
except TypeError:
1293+
return value # Python 2
1294+
1295+
self.set_clipboard(_bytes(str(text), 'UTF-8'), ClipboardContentType.PLAINTEXT, label)
12891296

12901297
def get_clipboard(self, content_type=ClipboardContentType.PLAINTEXT):
12911298
"""

0 commit comments

Comments
 (0)