I have a text file with 2000 lines of strings that are each 4 characters long. I need to type each of these strings into a website's input textbox and submit them one at a time. How do I do this? I know you can fill out forms in web pages with Selenium and python, but how do you fill out a textbox using data from a text file?
1 Answer
1) Read the content of the file
2) Find the element in which you want to insert text and submit it
3) do step 2 for all lines in file
from selenium import webdriver
with webdriver.Firefox() as driver:
with open('File_Name') as f:
for line in f:
driver.get('http://foo.com')
element = driver.find_element_by_id('sample_element')
element.send_keys(line.strip())
input_element.submit()