Skip to content

Handle UC Mode edge cases #2948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/raw_form_turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
sb.click('span:contains("9:00 PM")')
sb.highlight_click('input[value="AR"] + span')
sb.click('input[value="cc"] + span')
sb.scroll_to("iframe")
sb.scroll_to("div.cf-turnstile-wrapper")
sb.uc_gui_handle_cf()
sb.highlight("img#captcha-success", timeout=3)
sb.highlight_click('button:contains("Request & Pay")')
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pluggy==1.2.0;python_version<"3.8"
pluggy==1.5.0;python_version>="3.8"
py==1.11.0
pytest==7.4.4;python_version<"3.8"
pytest==8.2.1;python_version>="3.8"
pytest==8.3.1;python_version>="3.8"
pytest-html==2.0.1
pytest-metadata==3.0.0;python_version<"3.8"
pytest-metadata==3.1.1;python_version>="3.8"
Expand Down
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.28.6"
__version__ = "4.28.7"
17 changes: 14 additions & 3 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ def get_gui_element_position(driver, selector):
viewport_height = driver.execute_script("return window.innerHeight;")
viewport_x = window_rect["x"] + element_rect["x"]
viewport_y = window_bottom_y - viewport_height + element_rect["y"]
y_scroll_offset = driver.execute_script("return window.pageYOffset;")
viewport_y = viewport_y - y_scroll_offset
return (viewport_x, viewport_y)


Expand All @@ -688,7 +690,7 @@ def _uc_gui_click_x_y(driver, x, y, timeframe=0.25, uc_lock=False):
import pyautogui
pyautogui = get_configured_pyautogui(pyautogui)
screen_width, screen_height = pyautogui.size()
if x > screen_width or y > screen_height:
if x < 0 or y < 0 or x > screen_width or y > screen_height:
raise Exception(
"PyAutoGUI cannot click on point (%s, %s)"
" outside screen. (Width: %s, Height: %s)"
Expand Down Expand Up @@ -807,6 +809,16 @@ def _uc_gui_click_captcha(
frame = '[data-callback="onCaptchaSuccess"]'
else:
return
if driver.is_element_present('form[class*=center]'):
script = (
"""var $elements = document.querySelectorAll('form');
var index = 0, length = $elements.length;
for(; index < length; index++){
the_class = $elements[index].getAttribute('class');
new_class = the_class.replaceAll('center', 'left');
$elements[index].setAttribute('class', new_class);}"""
)
driver.execute_script(script)
if not is_in_frame or needs_switch:
# Currently not in frame (or nested frame outside CF one)
try:
Expand Down Expand Up @@ -977,7 +989,7 @@ def uc_gui_handle_cf(driver, frame="iframe"):
return
try:
found_checkbox = False
for i in range(10):
for i in range(24):
pyautogui.press("\t")
time.sleep(0.02)
active_element_css = js_utils.get_active_element_css(driver)
Expand All @@ -987,7 +999,6 @@ def uc_gui_handle_cf(driver, frame="iframe"):
time.sleep(0.02)
if not found_checkbox:
return
driver.execute_script('document.querySelector("input").focus()')
except Exception:
try:
driver.switch_to.default_content()
Expand Down
2 changes: 2 additions & 0 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -3418,6 +3418,8 @@ def get_gui_element_rect(self, selector, by="css selector"):
viewport_height = self.execute_script("return window.innerHeight;")
x = math.ceil(window_rect["x"] + i_x + element_rect["x"])
y = math.ceil(w_bottom_y - viewport_height + i_y + element_rect["y"])
y_scroll_offset = self.execute_script("return window.pageYOffset;")
y = int(y - y_scroll_offset)
if iframe_switch:
self.switch_to_frame()
if not self.is_element_present(selector, by=by):
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
'pluggy==1.5.0;python_version>="3.8"',
"py==1.11.0", # Needed by pytest-html
'pytest==7.4.4;python_version<"3.8"',
'pytest==8.2.1;python_version>="3.8"',
'pytest==8.3.1;python_version>="3.8"',
"pytest-html==2.0.1", # Newer ones had issues
'pytest-metadata==3.0.0;python_version<"3.8"',
'pytest-metadata==3.1.1;python_version>="3.8"',
Expand Down Expand Up @@ -262,7 +262,7 @@
'pdfminer.six==20221105;python_version<"3.8"',
'pdfminer.six==20240706;python_version>="3.8"',
'cryptography==39.0.2;python_version<"3.9"',
'cryptography==42.0.8;python_version>="3.9"',
'cryptography==43.0.0;python_version>="3.9"',
'cffi==1.15.1;python_version<"3.8"',
'cffi==1.16.0;python_version>="3.8"',
"pycparser==2.22",
Expand Down Expand Up @@ -300,6 +300,7 @@
# pip install -e .[selenium-wire]
"selenium-wire": [
'selenium-wire==5.1.0',
'pyOpenSSL==24.2.1',
'Brotli==1.1.0',
'blinker==1.7.0', # Newer ones had issues
'h2==4.1.0',
Expand Down