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.
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.
I’ve not personally worked with Selenium, though I did find a few posts that may hopefully help you out.
http://www.alittlemadness.com/2008/03/05/running-selenium-headless/
Click below to sign up and get $100 of credit to try our products over 60 days!
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.