1

I want to create a bot who log in discord. The problem is that discord appear with a captcha. I paid for 2captcha solution.

I solve the captcha but I don't know how to insert it because there are no button. There are iframe and I am not sure how to do.

I try several code but I am novice.

Can you help me to find a way to do that?

I am so helpful.

I can answer quickly.

Thanks a lot.

driver.get("https://discord.com/login")
driver.set_window_size(1080, 1024)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.NAME, "email")))
driver.find_element(By.NAME, "email").send_keys(DISCORD_EMAIL)
time.sleep(1)
driver.find_element(By.NAME, "password").send_keys(DISCORD_PASSWORD)
time.sleep(2)
driver.find_element(By.CSS_SELECTOR, 'button[type="submit"]').click()
try:
 captcha_iframe = WebDriverWait(driver, 10).until(
 EC.presence_of_element_located((By.CSS_SELECTOR, 'iframe[data-hcaptcha-widget-id]'))
 )
 site_key = driver.execute_script("return document.querySelector('iframe').src.split('sitekey=')[1].split('&')[0]")
 print("site key OK")
 #driver.switch_to.default_content()
 captcha_token = solve_captcha(site_key, "https://discord.com/login")
 time.sleep(3)
 driver.execute_script(f"""
 const iframe = document.querySelector('iframe[data-hcaptcha-widget-id]');
 console.log('Iframe:', iframe);
 if (!iframe) {{
 console.log('Iframe not found');
 return;
 }}
 const parent = iframe.parentElement.parentElement;
 console.log('Parent:', parent);
 if (!parent) {{
 console.log('Parent element not found');
 return;
 }}
 const reactPropsKey = Object.keys(parent).find(key => key.includes('reactProps'));
 console.log('reactPropsKey:', reactPropsKey);
 if (!reactPropsKey) {{
 console.log('reactProps key not found');
 return;
 }}
 if (!parent[reactPropsKey] || !parent[reactPropsKey].children || !parent[reactPropsKey].children.props || !parent[reactPropsKey].children.props.onVerify) {{
 console.log('onVerify function not found');
 console.log(parent[reactPropsKey]);
 return;
 }}
 parent[reactPropsKey].children.props.onVerify('{captcha_token}');
 console.log('Captcha verified successfully');
 """)
 time.sleep(2)
 # Capture console logs
 logs = driver.get_log('browser')
 for log in logs:
 print(log)
Ajeet Verma
4,5567 gold badges20 silver badges31 bronze badges
asked Jan 30, 2025 at 22:06
1
  • What is incorrect seems to be: driver.execute_script(...) Commented Jan 30, 2025 at 22:07

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.