Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: How to fill out form all at once with splinter/Browser?

Currently, I’m filling out the form on a site with the following:

browser.fill(‘form[firstname]’, ‘Mabel’)
browser.fill(‘form[email]’, ‘[email protected]’)
browser.select(‘form[color]’, ‘yellow’)

But the form gets filled out the form sequentially, one after the other. Is there a way to fill out the form all at once?

Thank you and will be sure to vote up and accept the answer!

like image 575
Dan Me Avatar asked Apr 21 '17 23:04

Dan Me


People also ask

How to automatically fill in online forms using JavaScript in Python?

Get the id tag of each field that you want to automatically fill in using the JavaScript script that the Python script is going to generate, by Inspecting the HTML element of each corresponding field of the online form (s). 2 .

How do I create a python script for an online form?

If your online form has fields that are selectable fields (with a drop-down menu) then get the id tags of each of these fields and add them to a .ini (text) file. Save this file with the same name as you will use for your Python script.

Is there a Python library to automate browser actions?

There are Python libraries and tools for automatizing browser actions. StackOverflow.com is not a place to ask for an recommendation for such a tool and thus moderators will close this question (SO is usually asking a help for particular problem, not for broad help and tutoriing requests).

How to fill in the online form with the same data?

With the code pasted, just press enter (with the focus inside the Console tab). Then the online form will be automatically filled in, with the same data contained within the PDF form document. We can check that the data filled into the online form is indeed the same as the one on the PDF form document.


1 Answers

Browser has a method called: fill_form(field_values)

It takes a dict parameter, with the field names, and the values, and it fills the form at once.

So you'll use browser.fill_form(dict) instead of browser.fill(field, value)

More info about Browser's API and its methods here :

https://splinter.readthedocs.io/en/latest/api/driver-and-element-api.html

like image 100
HakRo Avatar answered Oct 13 '22 01:10

HakRo