1

I have a SeleniumBase code like this

from seleniumbase import SB
from func_timeout import func_set_timeout, FunctionTimedOut

def checkbox():
    print('- click checkbox')
    checkbox = 'span#recaptcha-anchor'
    try:
        sb.wait_for_element(checkbox)
        sb.click(checkbox)
        sb.sleep(4)
    except FunctionTimedOut as e:
        print('-  checkbox:', e)

When I call checkbox() it gives error and the browser crashes quickly without clicking the checkbox

I tried replacing checkbox = 'id#recaptcha-anchor-label' checkbox = 'id#rc-anchor-center-item' but it didn't work

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
Kyomeki EL
  • 19
  • 1
  • Have you considered that reCAPTCHA is designed to prevent *exactly* what you’re attempting to do here…? – esqew Jan 02 '23 at 15:11

1 Answers1

-1

You might want to try avoiding the captcha altogether by running SeleniumBase in undetected-chromedriver mode (set uc=True, or run with --uc):

from seleniumbase import SB

with SB(uc=True) as sb:
    sb.open("https://nowsecure.nl/#relax")
    try:
        sb.assert_text("OH YEAH, you passed!", "h1", timeout=7)
        sb.post_message("Selenium wasn't detected!", duration=2)
        print("\n Success! Website did not detect Selenium! ")
    except Exception:
        print("\n Sorry! Selenium was detected!")

If you still need to go through the captcha, then make sure that if you need to click something in an iframe, that you switch to the iframe first, such as with sb.switch_to_frame("iframe").

Also, the sb.click(selector) method will automatically wait for the element, which means that calling sb.wait_for_element(selector) before that is unnecessary.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48