seleniumbase / SeleniumBase

📊 Blazing fast Python framework for web crawling, scraping, testing, and reporting. Supports pytest. Stealth abilities: UC Mode and CDP Mode.
https://seleniumbase.io
MIT License
5.49k stars 993 forks source link

How uc_click on coordinates? #2929

Closed LoadingT closed 4 months ago

LoadingT commented 4 months ago

I have a captcha, which requered click on Claudflare checkbox which inside a shadow root(closed), is there a uc_click(x,y) in selenium base? I can't find it in the documentation, it would be cool to add such a thing

mdmintz commented 4 months ago

Use sb.uc_gui_click_captcha() to click the CF CAPTCHA in UC Mode:

from seleniumbase import SB

with SB(uc=True, test=True) as sb:
    url = "https://seleniumbase.io/apps/turnstile"
    sb.uc_open_with_reconnect(url)
    sb.uc_gui_click_captcha()
    sb.assert_element("img#captcha-success", timeout=3)
    sb.set_messenger_theme(location="top_left")
    sb.post_message("SeleniumBase wasn't detected", duration=3)
wwangyu2 commented 4 months ago

don't work

======================================================== {tempCodeRunnerFile.python:3:SB} starts =========================================================
Traceback (most recent call last):
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\plugins\sb_manager.py", line 964, in SB
    yield sb
  File "C:\Users\cf\AppData\Local\Temp\tempCodeRunnerFile.python", line 7, in <module>
    sb.assert_element("img#captcha-success", timeout=5)
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\base_case.py", line 9421, in assert_element
    self.wait_for_element_visible(selector, by=by, timeout=timeout)
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\base_case.py", line 8846, in wait_for_element_visible
    return page_actions.wait_for_element_visible(
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\page_actions.py", line 503, in wait_for_element_visible
    timeout_exception(ElementNotVisibleException, message)
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\page_actions.py", line 254, in timeout_exception
    raise exc(msg)
seleniumbase.common.exceptions.ElementNotVisibleException: Message: 
 Element {img#captcha-success} was not visible after 5 seconds!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\plugins\sb_manager.py", line 991, in SB
    sb.tearDown()
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\base_case.py", line 16277, in tearDown
    log_helper.log_test_failure_data(
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\core\log_helper.py", line 289, in log_test_failure_data        
    log_file = codecs.open(basic_file_path, "w+", "utf-8")
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\codecs.py", line 905, in open
    file = builtins.open(filename, mode, buffering)
OSError: [Errno 22] Invalid argument: 'latest_logs\\SB\n    yield sb\n  File "C:\\Users\\cf\\AppData\\Local\\Temp\\tempCodeRunnerFile.line_3\\basic_test_info.txt'
********** ERROR: The test AND the tearDown() FAILED!
Traceback (most recent call last):
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\plugins\sb_manager.py", line 964, in SB
    yield sb
  File "C:\Users\cf\AppData\Local\Temp\tempCodeRunnerFile.python", line 7, in <module>
    sb.assert_element("img#captcha-success", timeout=5)
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\base_case.py", line 9421, in assert_element
    self.wait_for_element_visible(selector, by=by, timeout=timeout)
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\base_case.py", line 8846, in wait_for_element_visible 
    return page_actions.wait_for_element_visible(
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\page_actions.py", line 503, in wait_for_element_visible
    timeout_exception(ElementNotVisibleException, message)
  File "C:\Users\cf\AppData\Local\Programs\Python\Python310\lib\site-packages\seleniumbase\fixtures\page_actions.py", line 254, in timeout_exception      
    raise exc(msg)
seleniumbase.common.exceptions.ElementNotVisibleException: Message:
 Element {img#captcha-success} was not visible after 5 seconds!
=================================================== {tempCodeRunnerFile.python:3:SB} failed in 22.69s ====================================================