I'm trying to solve an invisible reCaptcha with an API, but I don't know how can I execute the callback function and send the token with selenium.
Below is the snippet of my code
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
from anticaptchaofficial.recaptchav2proxyless import *
def solve_recaptcha(site):
solver = recaptchaV2Proxyless()
solver.set_verbose(1)
solver.set_key("mykey")
solver.set_website_url(site)
solver.set_website_key("6LcmDCcUAAAAAL5QmnMvDFnfPTP4iCUYRk2MwC0-")
g_response = solver.solve_and_return_solution()
if g_response != 0:
return g_response
else:
return 0
site = 'https://recaptcha-demo.appspot.com/recaptcha-v2-invisible.php'
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options,executable_path='chromedriver.exe')
driver.get(site)
g_recaptcha = solve_recaptcha(site)
driver.execute_async_script("var token = '{}'; onSubmit(token);", g_recaptcha)
WebDriverWait(driver, 2).until(EC.visibility_of_element_located((By.XPATH, "//button[contains(text(), 'Submit ↦')]"))).click()
And this is the function:
function onSubmit(token) {
document.getElementById("demo-form").submit();
}
I receive this message from the site:
Note: Error code missing-input-response may mean the user just didn't complete the reCAPTCHA.
So, I'm not sure, but probably the the webdriver is not sending the var. And I don't know how should I proceed.
g-recaptcha-response, with this command:driver.execute_script("""document.getElementById("g-recaptcha-response").innerHTML = arguments[0]""", g_recaptcha),and click on submit. But it doesn't work too.