0

I am trying to write a program which can automatically fill in and submit a form in a web in particular time slot.

But i have no idea how and where to start. i searched this in google, but only resulting very general answer like using JavaScript, python. Can anyone tell me which languages should i learn first?

2
  • Please move this question to softwareengineering.stackexchange.com. Commented May 23, 2018 at 11:38
  • Unfortunately, this site is for specific questions about programming problems, not soliciting general advice or recommendations. Commented May 23, 2018 at 11:43

3 Answers 3

3

Despite the fact that the generic advice on this thread is quite good, it's pretty broad. I have tackled this problem myself, and despite the fact that I posted a fully functional example, it was deleted by a moderator, despite "theoretically answering the questions".

So, for anyone else looking to solve this problem, you will want to do the following: Use Selenium and openpyxl, these are two modules that are relatively straight forward and will perform this task perfectly.

You will use selenium to open your web page, and retrieve the relevant html elements that you wish to populate. I suggest finding elements by xPath if you aren't well versed in HTML. The Xpath finder google chrome addon will make this very easy to do.

The driver.get() and driver.find_element_by_xpath() will be the functions that you need.

We will use openpyxl to work with our excel sheet. 'load_workbook()' will load a workbook. We will then use the 'sheet = workbook.active' function to access a sheet from within the workbook.

We now have the functionality to open our website and select an excel sheet.

Now we need to assign cell values to variables, so that we can then populate the HTML form. We assign a variable to each COLUMN in the workbook. So if column A contained first_names we could assign that to by a variable by writing 'FNAME = sheet['A']. Now that we have a way of referring to cells within columns we can begin feeding the data into our HTML form.

We populate our form by using the .send_keys() function in Selenium.

first_name.send_keys(FNAME.value)

the .value makes sure that the correct value is displayed, as sometimes selenium will print the cell function rather than value, we do not want this to happen.

Now that we can print values to our HTML forms from our excel sheet we will need to iterate through each row. We do this with a simply while loop:

i = 1
x = 1
while x <= 50:
  first_name.send_keys(FNAME[i].value)
  i+=1
  x+=1
driver.quit

Once the loop occurs 50 times, the driver will quit, closing the browser and stopping the script.

Some other misc stuff you may find useful when trying to automate this:

driver.back()

time.sleep()

If you would like to see an actual working example feel free to PM me, as apparently posting it here doesn't contribute to the discussion.

Sign up to request clarification or add additional context in comments.

1 Comment

I think everything will work perfect but in my case while loading web page in intranet, browser does authentication via active directory and show my name on top right. While doing it via script I get HTML where clearly shown: "<h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2>"
0

The answers you found, as general as they are, are correct. I'll try to explain it to you.

As you are trying to automatize some activity, you have to use a script language to basically

  1. Get stuff references (like getting indexes, forms/fields IDs, etc)
  2. Insert/change stuff (like filling a field, following the field references)
  3. Save stuff (prepare a file, with field references and it's content, that can be injected to the specific system or website)

One example of script language is Python.

So you already have your script. Now you need to inject it on the page. The programming language that can do it for you is Javascript, or JS. It allows you to talk with the webpage, GETting data/references or POSTing data.

Comments

0

I suggest you to write a Python script using a library called Selenium Webdriver.

It will be easy to implement what you have in mind.

6 Comments

Is there any way to drive this action from an existing web application? I have a customer request to drag/drop a file with 100s of lines that all need to be entered into this 3rd party form. So they want to goto a site, drop the file, it parses out the lines, goes to the 3rd party site, and executes the form however many times required
Sure thing, you can execute Selenium from the backend in headless mode. If you have problems create a new question, you will easily find help.
tried and got bombed. I'm not actually sure where to post questions like these. any suggestions?
The suggestions were already provided in the answer there. I'd suggest you to implement your solution and see if it works. If it doesn't then you have an actual technical problem and you can ask a valid question here on Stackoverflow, for example. Something like "I tried this code but it doesn't work because I get the error XXX".
What you ask for is to get the solution built for you and that is something that will not happen on StackExchange. But you can achieve a similar result on different website offering such service, clearly.
|

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.