Elantris
New member
I'm trying to using 2Captcha to solve a recaptcha v2. When I run my code, it successfully gets the recaptcha result and stores it in result['code'], however when I execute the below code to submit, it seems the page only refreshes and the recaptcha does not get solved. Excuse my for my errors, I am extremely new to coding, and therefor my code is very crude and experimental. I am able to solve the captcha at https://2captcha.com/demo/recaptcha-v2?level=high using this code slightly modified, but haven't been able to get it working for my purpose. Can anyone explain to me what I could be doing differently?
I have included my full code below as well
Thank you!
driver.find_element_by_id("g-recaptcha-response").submit()
I have included my full code below as well
Code:
from selenium import webdriver
import time
import json
import sys
import os
from twocaptcha import TwoCaptcha
loginInfo = json.load(open('logn.json'))
username = loginInfo['username']
password = loginInfo['password']
driver = webdriver.Firefox()
driver.get("https://www.gaiaonline.com/")
loginButton = driver.find_element_by_xpath('//*[@id="login"]')
loginButton.click()
time.sleep(1)
usernameField = driver.find_element_by_xpath('//*[@id="username"]')
usernameField.send_keys(username)
passwordField = driver.find_element_by_xpath('//*[@id="password"]')
passwordField.send_keys(password)
rememberMe = driver.find_element_by_xpath('//*[@id="autologin"]')
rememberMe.click()
loginButton2 = driver.find_element_by_xpath('//*[@id="signInButton"]')
loginButton2.click()
time.sleep(5)
driver.get("https://www.gaiaonline.com/forum/compose/entry/new/79469475/")
time.sleep(4)
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
api_key = os.getenv('APIKEY_2CAPTCHA', 'My_API_KEY')
solver = TwoCaptcha(api_key)
result = solver.recaptcha(sitekey=driver.find_element_by_class_name("g-recaptcha").get_attribute("data-sitekey"),
url=driver.current_url)
print(result['code'])
driver.execute_script('var element=document.getElementById("g-recaptcha-response"); element.style.display="";')
driver.execute_script("""
document.getElementById("g-recaptcha-response").innerHTML = arguments[0]
""", result['code'])
time.sleep(3)
driver.find_element_by_id("g-recaptcha-response").submit()
Thank you!