I'm trying to run the callback function for the hcaptcha but it keeps giving me the null (reading 'appendChild') error, If anyone has any other suggestions, I'd appreciate it.
import os
import threading
import time
import nopecha
import undetected_chromedriver as uc
import tkinter as tk
def solvehCaptcha():
print("başlatıldı!")
nopecha.api_key = '\*'
# Call the Token API
token = nopecha.Token.solve(
type='hcaptcha',
sitekey='b4c45857-0e23-48e6-9017-e28fff99ffb2',
url='https://nopecha.com/demo/hcaptcha#easy',
)
print(token)
browser.execute_script(f'''
document.querySelector('[id^="h-captcha-response-"]').innerHTML = "{token}"
''')
js_script = f"""
let captchaElement = document.getElementById('captcha')
let inputElement = document.createElement('input');
inputElement.setAttribute('type', 'hidden');
inputElement.setAttribute('name', 'response_token');
inputElement.setAttribute('value', "{token}");
captchaElement.appendChild(inputElement)
"""
browser.execute_script(js_script)
options = uc.ChromeOptions()
options.set_capability("detach", True)
browser = uc.Chrome(options=options)
browser.get('https://nopecha.com/demo/hcaptcha#easy')
root = tk.Tk()
root.geometry("300x300")
btn = tk.Label(root, text="Başlat", bg="Black", fg="white")
btn.pack(side="top", anchor="center")
btn.bind("\<Button-1\>", lambda e: threading.Thread(target=solvehCaptcha).start())
root.mainloop()
Error result:
Exception in thread Thread-2: Traceback (most recent call last): File "C:\Users\fatih\AppData\Local\Programs\Python\Python39\lib\threading.py", line 950, in _bootstrap_inner self.run() File "C:\Users\fatih\AppData\Local\Programs\Python\Python39\lib\threading.py", line 888, in run self._target(*self._args, **self._kwargs) File "C:\Users\fatih\OneDrive\Masaüstü\Python\reklam-project\test2.py", line 36, in solvehCaptcha browser.execute_script(js_script) File "C:\Users\fatih\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 500, in execute_script return self.execute(command, {"script": script, "args": converted_args})["value"] File "C:\Users\fatih\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute self.error_handler.check_response(response) File "C:\Users\fatih\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read properties of null (reading 'appendChild') (Session info: chrome=113.0.5672.64) Stacktrace: Backtrace: GetHandleVerifier [0x00FE8893+48451] (No symbol) [0x00F7B8A1] (No symbol) [0x00E85058] (No symbol) [0x00E883F1] (No symbol) [0x00E89DEB] (No symbol) [0x00EDCDD9] (No symbol) [0x00ECA2BC] (No symbol) [0x00EDC482] (No symbol) [0x00ECA0B6] (No symbol) [0x00EA7E08] (No symbol) [0x00EA8F2D] GetHandleVerifier [0x01248E3A+2540266] GetHandleVerifier [0x01288959+2801161] GetHandleVerifier [0x0128295C+2776588] GetHandleVerifier [0x01072280+612144] (No symbol) [0x00F84F6C] (No symbol) [0x00F811D8] (No symbol) [0x00F812BB] (No symbol) [0x00F74857] BaseThreadInitThunk [0x75800099+25] RtlGetAppContainerNamedObjectPath [0x77917B6E+286] RtlGetAppContainerNamedObjectPath [0x77917B3E+238]
I want to make the hcaptcha callback without submit button, but I get error: Cannot read properties of null (reading 'appendChild')