from seleniumwebdrivercommonactionchains import ActionChains
try:
chrome_driver = self.controller.chrome_driver
print("current_url: ", chrome_driver.current_url)
input("Press Enter key to continue...")
chrome_driver.switch_to.default_content()
print("Complete switch to default content")
reCAPTCHA iframe 찾기
frames = chrome_driver.find_elements(By.TAG_NAME, "iframe")
input("Press Enter key to continue...")
recaptcha_iframe = None
for frame in frames:
if "reCAPTCHA" in frame.get_attribute("title"):
recaptcha_iframe = frame
break
input("Press Enter key to continue...")
if recaptcha_iframe:
reCAPTCHA iframe으로 전환
chrome_driver.switch_to.frame(recaptcha_iframe)
print("Complete switch to reCAPTCHA iframe")
input("Press Enter key to continue...")
checkbox = WebDriverWait(chrome_driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.recaptcha-checkbox-border")))
actions = ActionChains(chrome_driver)
user_input = input("Do you want to click the checkbox? (Y/N): ")
if user_input.lower() == "y":
actions.move_to_element(checkbox).pause(random.uniform(1, 3)).click().perform()
else:
print("You didn't click the checkbox")
else:
print("No reCAPTCHA")
chrome_driver.switch_to.default_content()
except Exception as e:
print("\n\nNo reCAPTCHA\n\n")