akaihola / keke

WhatsApp AI chatbot
MIT License
1 stars 0 forks source link

Pasting from clipboard repeats the first copied content #4

Open akaihola opened 1 year ago

akaihola commented 1 year ago

Extended Unicode characters (e.g. emojis) can't be typed using Selenium send_keys().

The work-around is to copy the desired content into the clipboard and send a Ctrl-V instead.

Clipboard management on the Python side can be done e.g. with pyclip or pyperclip. The backend can be e.g. xsel, xclip or wl-clipboard.

With all of these tools, the symptom is the same: The first copied string is pasted perfectly. But every subsequent paste writes the initial copied string, no matter what else has been copied into the clipboard.

pyclip.paste() and pyperclip.paste() see the freshly copied string. Typing Ctrl-V manually into the automated browser always pastes the right thing.

After restarting Keke, the clipboard works correctly again, but only once.

akaihola commented 1 year ago

This can be reproduced by copying content manually using Ctrl-C and then calling message_field.send_keys(Keys.CONTROL, "v").

akaihola commented 1 year ago

Focusing the automated browser window by clicking on the title bar somehow refreshes the clipboard, and pasting works correctly again.