Is it possible to imitate keyboard input via Command Line or Python Code in digitalocean headless Ubuntu?

Is it possible to imitate Keyboard input via Command Line or Python Code? If possible, do I have to additionally install some kind of Dependencies to make keyboard input? I am worried that I can’t generate keyboard input because digitalocean linux doesn’t have real keyboard or input device attached to it.

I am currently using Selenium with python, and there are lines of code which imitates keyboard input to a Firefox browser. For example,

from selenium.webdriver.common.keys import Keys driver.find_element_by_tag_name(‘body’).send_keys(Keys.CONTROL + ‘t’)

Unfortunately, this code doesn’t work, after trying a lot of tests.

I found that the code I used actually runs well on my local linux, which has real keyboard device.

I think I’m sure that being unable to give keyboard input is not Selenium nor other third-party software problem. I guess the problem resides in the fact that Ubuntu is headless and doesn’t have input device attached to it.


The code (from selenium.webdriver.common.keys import Keys driver.findelementbytagname(‘body’).send_keys(Keys.CONTROL + ‘t’)) is in digitalocean Ubuntu, and Everytime I run the code I can confirm that the code isn’t working.

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.