0

I am trying to bypass (auto solving) captcha while login a website. But when I run an JS scripts after received the answer code from 2Captcha, I got javascript error: Illegal invocation. Here is my code:

u1 = f"https://2captcha.com/in.php?key={API_KEY}&method=userrecaptcha&googlekey={data_sitekey}&pageurl={page_url}&json=1&invisible=1"
    r1 = requests.get(u1)
    print(r1.json())
    rid = r1.json().get("request")
    u2 = f"https://2captcha.com/res.php?key={API_KEY}&action=get&id={int(rid)}&json=1"
    time.sleep(5)
    while True:
        r2 = requests.get(u2)
        print(r2.json())
        if r2.json().get("status") == 1:
            form_token = r2.json().get("request")
            break
        time.sleep(5)
    write_tokon_js = f'document.getElementById("g-recaptcha-response").innerHTML="{form_token}";'
    submit_js = "document.createElement('form').submit.call(document.getElementsByClassName('button')[0]);"
    driver.execute_script(write_tokon_js)
    time.sleep(3)
    driver.execute_script(submit_js)
    time.sleep(10)

At first, I tried to submit form using document.getElementsByClassName('button')[0].submit() but after a while of researching on google and stackoverflow, i realized that a website i am trying to automate having so many button class and it won't work so i changed to the above code.

I think there is something wrong in my submit_js but I don't know exactly why, I am not familiar with Javascript . Please help me fix it.

EDIT 1 Here is the HTML code of a button i am trying to submit:

<p class="submit">
<input type="hidden" name="action" value="register_handler">
<input type="hidden" name="jnews_nonce" value="36b5269a22">
<input type="submit" name="jeg_login_button" class="button" value="Đăng ký" data-process="Processing . . ." data-string="Đăng ký">
</p>

I think the problem is this is just a button, not a form, that's why I can't submit it. But I don't know how to submit (I tried to click the button using Webdriver after put in code received from 2captcha inside "g-recaptcha-response" but it always return Invalid Captcha, seem like the only way to continue is submit using JS scripts but I still don't know how)

0 Answers0