简体   繁体   中英

Send token from 2Captcha API to solve Hcaptcha using Python Selenium Chromedriver

I am trying to solve the Hcaptcha page on a website protected by Cloudfare

Website to access: https://carmanuals2.com/mazda/3-hatchback-2020-owner-s-manual-114463

I followed the instruction on Recatcha API and able to get token that are suppose to be placed in these two fields:

<textarea id="g-recaptcha-response-0418tkobioj8" name="g-recaptcha-response" style="display: none;"></textarea>
<textarea id="h-captcha-response-0418tkobioj8" name="h-captcha-response" style="display: none;"></textarea>

API Documentation: https://2captcha.com/2captcha-api#solving_hcaptcha

Next step is to place the tokens on these two elements, However, I get a error as selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

Here is a snipppet of my code, where I try to place the token I received (captcha)

        sitekey = site["src"].split("=")[-1]
        
        currenturl = driver.current_url
        print (currenturl)


        flag, captcha = solve_h_captcha(sitekey,currenturl)

        username = driver.find_element_by_name('g-recaptcha-response')
        username.send_keys(captcha)
        time.sleep(2)
        
        username = driver.find_element_by_name('h-captcha-response')
        username.send_keys(captcha)
        time.sleep(2)

#        username.send_keys(captcha)
        time.sleep(0.5)

Thanks a lot!!!!

You probably need to do things like that from js:

driver.execute_script("""
  let [captcha] = arguments
  document.querySelector('[name="h-captcha-response"]').innerHTML = captcha
  document.querySelector('[name="g-captcha-response"]').innerHTML = captcha
""", captcha)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM