faizan mehmood
faizan mehmood

Reputation: 21

Submitting Recaptcha v2 with selenium when no submit button is present python

I am using services of ImageTyperz for solving the captcha but unable to submit a response back to the website. There is no submit button but a callback is there which should be called. When i call this callback i get selenium.common.exceptions.TimeoutException: Message: script timeout exception. The function which is called looks like this

                    function solvedCaptcha(payload) {
                        const timeoutMs = 10000;
                        protectionSubmitCaptcha("recaptcha", payload, timeoutMs, "3:wi5qRb7c93CuT63y1uUslQ==:BXJXyJOzlEFA5FdRRQw7hUgzO5M4FIz8DegFPzs6fER0MRWYM+P2Vac+z3qKo5UxmDqMuThgGaT0hK+Tu6Zj0b5sprMSQI7P2Wv7fAj7aFUC20NO7VN6NtyyTehmQcxscyQBUqvlXbyTct2rUi81hPRk9fp7Vt32kGZspgx0v4tbTmDK2xMG1mj5nOVN9TL5zs88iYQDfSa2lKcdLrhYl5VcEDh5rAAte8d6rvead+5oY0a8B7fennPu2+36wZboyg4JJ1yMSpMmZ8Nk47/R/Q==:BwSP9POMwcERVjmiYuOpMZkDQmQS1ksQSij5jk8Fs8A=").then(function() {
                            window.location.reload(true);
                        });
                    }
                

I am running the following command

driver.execute_async_script("var payload = " + str(recaptcha_response) + ";" + "solvedCaptcha(payload);")

Here recaptcha_response is the response dict got from ImageTyperz api.

Upvotes: 1

Views: 1995

Answers (1)

Crazy Programming
Crazy Programming

Reputation: 267

I solved the problem

I've finally managed to resolve this myself. In case anyone else is struggling with a similar issue, here was my solution:

  • Open the console and execute the following cmd: ___grecaptcha_cfg.clients
  • Find the path which has the callback function, in my case it's ___grecaptcha_cfg.clients[0].O.O
  • Use the following code: driver.execute_script(f"___grecaptcha_cfg.clients[0].O.O.callback('{new_token}')") (Remember to change the path accordingly)

This Article will help you to find the ___grecaptcha_cfg.clients of your recaptcha site

driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "{}";'.format(g_response))   
driver.execute_script(f"___grecaptcha_cfg.clients[0].O.O.callback('{g_response}')")

Upvotes: 6

Related Questions