How to submit google captcha without submit button?

Naborrlds

New member
I'm writing an automation script using python and selenium, but I'm having a problem with the last step as the previous steps had submit button under captcha so the form was submitted. I was thinking about pay loading directly captcha response to the site but I didn't find any method to do this.

I'm using 2captcha automated resolving.

I have found this video that submits captcha I've looked into the code but I can't tell if it will work with my code

This is part of my code relevant to this question
Code:
def captchaHome():
    driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
    service_key = 'xxxxxxxxxxxxxxxxxxxxxx'  # 2captcha service key
    google_site_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'  # reCAPTCHAのdata-sitekey
    pageurl = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    url = "http://2captcha.com/in.php?key=" + service_key + "&method=userrecaptcha&googlekey=" + google_site_key + "&pageurl=" + pageurl
    resp = requests.get(url)
    if resp.text[0:2] != 'OK':
        quit('Service error. Error code:' + resp.text)
    captcha_id = resp.text[3:]
    fetch_url = "http://2captcha.com/res.php?key=" + service_key + "&action=get&id=" + captcha_id

    for i in range(1, 10):
        time.sleep(10)  # wait 10 sec.
        resp = requests.get(fetch_url)
        if resp.text[0:2] == 'OK':
            break
    print('Google response token: ', resp.text[3:])
    return resp.text[3:]

capHome = captchaHome()
driver.find_element_by_id('g-recaptcha-response').send_keys(capHome)


This is a code from the site I want to submit
Code:
 function show(classNames) {
            classNames.forEach(function(className) {
              document.querySelector(className).classList.remove('hidden');
            });
          }

          function hide(classNames) {
            classNames.forEach(function(className) {
              document.querySelector(className).classList.add('hidden');
            });
          }

          function showAnimation() {
            hide(['.challenge', '.error', '.success']);
            show(['.redeem', '.animation']);
          }

          function showSuccess() {
            hide(['.challenge', '.error']);
            show(['.redeem', '.success', '.animation']);
          }

          function showError() {
            hide(['.challenge', '.success', '.animation']);
            show(['.redeem', '.error']);
          }

          // used in data-callback
          function redemptionValidation(captchaResponse) {
            showAnimation();

            function reqListener() {
              if (this.status >= 200 && this.status < 400) {
                var redirectUrl = this.responseText;
                showSuccess();
                setTimeout(function() {
                  window.location.replace(redirectUrl);
                }, 3000);
              } else {
                showError();
              }
            }

            function reqErrListener() {
              showError();
            }


            var req = new XMLHttpRequest();
            req.addEventListener('load', reqListener);
            req.addEventListener('error', reqErrListener);
            req.open('POST', '/googlehome/redeem/getcode/');
            req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            req.send('g-recaptcha-response=' + encodeURIComponent(captchaResponse));
          }

So I want to submit captcha without submit button so it can redirect me to next step.

edit:

I was thinking about payloading submit button to the site but I can't find any way to do this something like this

Code:
// 1. Create the button
var button = document.createElement("button");
button.innerHTML = "Do Something";

// 2. Append somewhere
var cap = document.getElementsByTagName("body")[0];
cap.appendChild(button);

Then find it with selenium and click()