1

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
  • you have to read the data from the file, then get the textbox element with selenium then send text to that textbox and submit Commented Sep 30, 2018 at 5:30

1 Answer 1

3

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.