我有一个简单的程序,使用 Selenium 登录网站,使用 2captcha 解决 reCAPTCHA,并完成登录过程。但是,在解决 reCAPTCHA 并将其加载到带有“g-recaptcha-response”ID 的文本区域后,当我单击登录按钮时,网站仍然给我一个“必填字段不得为空”错误,并且不会让我继续。可能是什么问题?
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)
这是当前结果:在此处输入图像描述 并且错误来自网站,而不是 reCAPTCHA。我认为这个问题与2captcha无关,而更有可能与Selenium有关。
这里也有同样的问题。有更新吗?