Skip to content

Commit 7abc5e4

Browse files
committed
Support "Friendly Captcha" solving in async mode
1 parent 184f079 commit 7abc5e4

File tree

1 file changed

+48
-0
lines changed
  • seleniumbase/undetected/cdp_driver

1 file changed

+48
-0
lines changed

seleniumbase/undetected/cdp_driver/tab.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,6 +1406,11 @@ async def __on_an_incapsula_hcaptcha_page(self, *args, **kwargs):
14061406
return True
14071407
return False
14081408

1409+
async def __on_a_friendly_captcha_page(self, *args, **kwargs):
1410+
if await self.is_element_visible('iframe[data--frc-frame-id]'):
1411+
return True
1412+
return False
1413+
14091414
async def __on_a_g_recaptcha_page(self, *args, **kwargs):
14101415
await self.sleep(0.4) # reCAPTCHA may need a moment to appear
14111416
source = await self.get_html()
@@ -1514,6 +1519,46 @@ async def __cdp_click_incapsula_hcaptcha(self):
15141519
print(" <DEBUG> hCaptcha was NOT clicked!")
15151520
return False
15161521

1522+
async def __gui_click_friendly_captcha(self):
1523+
selector = 'iframe[data--frc-frame-id]'
1524+
if await self.is_element_visible('iframe[data--frc-frame-id]'):
1525+
element = await self.find_element_by_text(selector)
1526+
else:
1527+
return False
1528+
await self.sleep(0.55)
1529+
x_offset = 27
1530+
y_offset = 34
1531+
was_clicked = False
1532+
gui_lock = AsyncFileLock(constants.MultiBrowser.PYAUTOGUILOCK)
1533+
async with gui_lock:
1534+
await self.bring_to_front()
1535+
await self.sleep(0.056)
1536+
if "--debug" in sys.argv:
1537+
displayed_selector = "`%s`" % selector
1538+
if '"' not in selector:
1539+
displayed_selector = '"%s"' % selector
1540+
elif "'" not in selector:
1541+
displayed_selector = "'%s'" % selector
1542+
print(
1543+
" <DEBUG> click_with_offset(%s, %s, %s)"
1544+
% (displayed_selector, x_offset, y_offset)
1545+
)
1546+
with suppress(Exception):
1547+
await element.mouse_click_with_offset_async(
1548+
x=x_offset, y=y_offset, center=False
1549+
)
1550+
was_clicked = True
1551+
await self.sleep(0.075)
1552+
if was_clicked:
1553+
# Wait a moment for the click to succeed
1554+
await self.sleep(0.75)
1555+
if "--debug" in sys.argv:
1556+
print(" <DEBUG> Friendly Captcha was clicked!")
1557+
return True
1558+
if "--debug" in sys.argv:
1559+
print(" <DEBUG> Friendly Captcha was NOT clicked!")
1560+
return False
1561+
15171562
async def get_element_rect(self, selector, timeout=5):
15181563
element = await self.select(selector, timeout=timeout)
15191564
coordinates = None
@@ -1649,6 +1694,9 @@ async def solve_captcha(self):
16491694
elif await self.__on_an_incapsula_hcaptcha_page():
16501695
result = await self.__cdp_click_incapsula_hcaptcha()
16511696
return result
1697+
elif await self.__on_a_friendly_captcha_page():
1698+
result = await self.__gui_click_friendly_captcha()
1699+
return result
16521700
else:
16531701
return False
16541702
selector = None

0 commit comments

Comments
 (0)