2

Is it possible to fill all the fields on the page at once instead of one by one?

Right now I have

driver.find_element_by_id('1').send_keys(input1)
driver.find_element_by_id('2').send_keys(input2)
driver.find_element_by_id('3').send_keys(input3)

and it goes one by one taking a while to fill a form.

6
  • Are you concerned about the time it takes to fill out a form, or the amount of code used? Commented Sep 27, 2016 at 18:25
  • I'm concerned with the time it takes. Anyway to fill all fields at once? Commented Sep 28, 2016 at 23:06
  • I don't see how it can be taking any significant amount of time. Have you timed it? Commented Sep 29, 2016 at 0:18
  • So to fill a form with 5 inputs it takes about 3 seconds. Not much but it has to fill 1000s of forms which adds up. That's why I want to get it down to less than 1 second. Only possibly by having it input all fields at once. Commented Sep 29, 2016 at 0:25
  • The only way to do what you want is to not use a browser at all, but to communicate directly with the webserver via a POST call, supplying appropriate data for each named input field. Have a look at the requests python module. Commented Sep 29, 2016 at 2:59

1 Answer 1

1

You may construct a dict in python to store the values corresponding to id and Iterate over it to fill up the corresponding data.

input_mapping = {"1": "input1", "2": "input2", "3": "input3"}

for key, value in input_mapping.items():
    driver.find_element_by_id(key).send_keys(value)

But the above approach won't be sequential. as the dictionary maintains no order on it's own. So it would be a better choice to use collections.OrderedDict() if the order really matters

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.