What code would I use to input text into a box (not edit text, something along the lines of a message bot)?
Say I run the code, it opens a webpage and inputs text into a (e.g.) search box.
Thanks!
What code would I use to input text into a box (not edit text, something along the lines of a message bot)?
Say I run the code, it opens a webpage and inputs text into a (e.g.) search box.
Thanks!
You can use the Selenium library to create a bot in Python that inputs texts into a webpage.
According to their description, "the selenium package is used automate web browser interaction from Python."
You can install it by typing in the terminal:
pip install selenium
Then you'll have to build a set of instructions to tell the program what you want to do.
Example:
TASKS:
1. open a new Firefox browser
2. load the Yahoo homepage
3. search for “seleniumhq”
4. close the browser
CODE:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('http://www.yahoo.com')
assert 'Yahoo' in browser.title
elem = browser.find_element_by_name('p') # Find the search box
elem.send_keys('seleniumhq' + Keys.RETURN)
browser.quit()
Also, read the Selenium Docs and take a look at a few videos to understand how can you build your own web bot!