Solution 1 :

Using selenium and using requests are 2 different things, selenium uses your browser to submit the form via the html rendered UI, Python requests just submits the data from your python code without the html UI, it does not involve “clicking” the submit button.

The “submit” button in this case just merely triggers the browser to POST the form values.

However your backend will validate against the “recaptcha” token, so you will need to work around that.

Solution 2 :

Recommend u fiddling requests.

https://www.telerik.com/fiddler

And them recreating them.

James`s answer using selenium is slower than this.

Problem :

I created a program to fill out an HTML webpage form in Selenium, but now I want to change it to requests. However, I’ve come across a bit of a roadblock. I’m new to requests, and I’m not sure how to emulate a request as if a button had been pressed on the original website. Here’s what I have so far –

import requests
import random
emailRandom = ''
for i in range(6):        
    add = random.randint(1,10)
    emailRandom += str(add)
payload = {
    'email':emailRandom+'@redacted',
    'state_id':'34',
    'tnc-optin':'on',   
}
r= requests.get('redacted.com', data=payload)

The button I’m trying to “click” on the webpage looks like this –

<div class="button-container">
    <input type="hidden" name="recaptcha" id="recaptcha">
    <button type="submit" class="button red large">ENTER NOW</button>
</div>

What is the default/”clicked” value for this button? Will I be able to use it to submit the form using my requests code?

Comments

Comment posted by wadu

Right. I know that, sorry. I know that it requires me sending a payload, I just don’t know what the “clicked” value of that element is, so I can send it in my requests payload

Comment posted by wadu

What I need to know about the button is how i can trigger it.

Comment posted by James Lin

When you use requests in python, you don’t “trigger” the button, the button does not exist, because you don’t have a rendered front end.

Comment posted by James Lin

I am not suggesting to use selenium, the OP mentioned it and I thought he got confused with them.

Comment posted by wadu

Hi, I downloaded fiddler and added the keys and values I found in the composer. How will this help me find a solution to my problem?

Comment posted by Strings

Hello, you can simply recreate these requests following data you have sent.

By