Skip to content

fix python3 set_clipboard error#267

Merged
KazuCocoa merged 2 commits intoappium:masterfrom
KazuCocoa:fix-set-clipboard-python3
Oct 31, 2018
Merged

fix python3 set_clipboard error#267
KazuCocoa merged 2 commits intoappium:masterfrom
KazuCocoa:fix-set-clipboard-python3

Conversation

@KazuCocoa
Copy link
Copy Markdown
Member

Python 3 requires encoding in bytes. Python 2 doesn't.
close #265

Python 3

>>> driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
>>> driver.set_clipboard_text("hello")
>>> b = driver.get_clipboard()
>>> b.decode()
'hello'
>>> driver.set_clipboard_text("ありがとう")
>>> b = driver.get_clipboard()
>>> b.decode()
'ありがとう'

Python 2

>>> driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
>>> driver.set_clipboard_text("ありがとう")
>>> b = driver.get_clipboard()
>>> print(unicode(b.decode('UTF-8')))
ありがとう
>>> driver.set_clipboard_text("hello")
>>> b = driver.get_clipboard()
>>> print(unicode(b.decode('UTF-8')))
hello

"""
self.set_clipboard(bytes(text.encode('UTF-8')), ClipboardContentType.PLAINTEXT, label)

def _bytes(value, encoding):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to put this helper method into some separate helper module?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so, but nothing method used bytes so far. I'd like to extract here in next time.

@KazuCocoa KazuCocoa merged commit af1988e into appium:master Oct 31, 2018
@KazuCocoa KazuCocoa deleted the fix-set-clipboard-python3 branch October 31, 2018 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

driver.set_clipboard() and driver.set_clipboard_text doesn't work

2 participants