0
import os
def add_to_clipboard(text):
    import tempfile
    with tempfile.NamedTemporaryFile("w") as fp:
        fp.write(text)
        fp.flush()
        command = "xclip < {}".format(fp.name)
        os.system(command)
tried this .didnt work.

python selenium.I am automating stripe gateway but every time i send keys i.e. cc number or exp date. it get disordered. i found copy pasting the simplest fix. so i wanna know how to copy string inside a variable. i am using ubuntu 20.I tried pyperclip . some custom made functions from stack overflow . but none of em is working.

  • did you try `xclip` directly in console? It may have some options. As I remeber it may use system clipboard or private clipboard - primary and secondary clipboard. – furas Jul 24 '21 at 09:01
  • naah i tried in vscode – godsonnnnnn Jul 24 '21 at 09:02
  • `<` expect filename - if you want to send text then you may need `<<<` instead of `<`. But it probably need the newest `bash 4.0` OR you should use `echo text | xclip` – furas Jul 24 '21 at 09:03
  • i am kinda new to all these things and linux. i cant get it what u r trying to tell. – godsonnnnnn Jul 24 '21 at 09:04
  • try `pyperclip` its cross platform and just works from my experience – Joran Beasley Jul 24 '21 at 09:06
  • `"xclip <<< {}".format(text)` or `"echo {} | xclip".format(text)` and you don't need file – furas Jul 24 '21 at 09:06
  • I think you should rather show problem with sending keys instead of using clipoard because it can be [XYProblem](https://xyproblem.info/) - you have problem with send key (X Problem) and you try to resolve it with clipboard but it makes problem (Y Problem) and you ask how to resolve it (Y Problem) but you should ask how to resolve original problem (X Problem) – furas Jul 24 '21 at 09:08
  • @furas i chkd on stackover flow peeps were trying to solve it. but it wasnt 100% working method. pyperclip worked now thanks joran – godsonnnnnn Jul 24 '21 at 09:15
  • Does this answer your question? [How do I copy a string to the clipboard?](https://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard) – Kaihaku Jul 24 '21 at 09:23

0 Answers0