Berkay Kaya
Berkay Kaya

Reputation: 3

Selenium and 2captcha projects encountering 'g-recaptcha-response' problem

I have a simple program that uses Selenium to log into a website, solves the reCAPTCHA using 2captcha, and completes the login process. However, after solving the reCAPTCHA and loading it into the textarea with the 'g-recaptcha-response' ID, when I click on the login button, the website still gives me a 'Required field must not be blank' error and won't let me proceed. What could be the problem?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from solveRecaptcha import solveRecaptcha
import json

accounts = json.load(open('accounts.json', 'r', encoding='utf-8'))

options = Options()
options.binary_location = r'C:\Program Files\Firefox Developer Edition\firefox.exe'
driver = webdriver.Firefox(options=options)
driver.get('link')
driver.implicitly_wait(10)
driver.find_element(By.ID, 'email-input').send_keys(accounts['email'])
driver.find_element(By.ID, 'password-input').send_keys(accounts['password'])
result = solveRecaptcha("sitekey", "link")
WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, 'g-recaptcha-response'))
)
driver.execute_script("document.getElementById('g-recaptcha-response').innerHTML = " + "'" + result + "'") # this line works correct with no errors, i can see the result with inspect element
driver.find_element(By.ID, 'login-btn').click() # but when i click the button, recaptcha says like "Required field must not be blank"
driver.implicitly_wait(1000)

this is current result: enter image description here and the error is coming from the website, not the reCAPTCHA. I think the problem is not related to 2captcha, but more likely to be related to Selenium.

Upvotes: 0

Views: 436

Answers (0)

Related Questions