Skip to content

Commit d9dd888

Browse files
committed
Upgrade CDP Mode
1 parent e12c71a commit d9dd888

File tree

5 files changed

+66
-33
lines changed

5 files changed

+66
-33
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -985,17 +985,15 @@ def __install_pyautogui_if_missing():
985985
import pyautogui
986986
with suppress(Exception):
987987
use_pyautogui_ver = constants.PyAutoGUI.VER
988-
if pyautogui.__version__ != use_pyautogui_ver:
989-
del pyautogui
990-
shared_utils.pip_install(
991-
"pyautogui", version=use_pyautogui_ver
992-
)
988+
u_pv = shared_utils.make_version_tuple(use_pyautogui_ver)
989+
pv = shared_utils.make_version_tuple(pyautogui.__version__)
990+
if pv < u_pv:
991+
del pyautogui # To get newer ver
992+
shared_utils.pip_install("pyautogui", version="Latest")
993993
import pyautogui
994994
except Exception:
995995
print("\nPyAutoGUI required! Installing now...")
996-
shared_utils.pip_install(
997-
"pyautogui", version=constants.PyAutoGUI.VER
998-
)
996+
shared_utils.pip_install("pyautogui", version="Latest")
999997
try:
1000998
import pyautogui
1001999
except Exception:

seleniumbase/core/sb_cdp.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,12 @@ def send_keys(self, selector, text, timeout=None):
912912
element.scroll_into_view()
913913
if text.endswith("\n") or text.endswith("\r"):
914914
text = text[:-1] + "\r\n"
915+
elif (
916+
element.tag_name == "textarea"
917+
and "\n" in text
918+
and "\r" not in text
919+
):
920+
text = text.replace("\n", "\r")
915921
element.send_keys(text)
916922
self.__slow_mode_pause_if_set()
917923
self.loop.run_until_complete(self.page.sleep(0.025))
@@ -927,6 +933,12 @@ def press_keys(self, selector, text, timeout=None):
927933
if text.endswith("\n") or text.endswith("\r"):
928934
submit = True
929935
text = text[:-1]
936+
elif (
937+
element.tag_name == "textarea"
938+
and "\n" in text
939+
and "\r" not in text
940+
):
941+
text = text.replace("\n", "\r")
930942
for key in text:
931943
element.send_keys(key)
932944
time.sleep(0.044)
@@ -947,6 +959,12 @@ def type(self, selector, text, timeout=None):
947959
element.clear_input()
948960
if text.endswith("\n") or text.endswith("\r"):
949961
text = text[:-1] + "\r\n"
962+
elif (
963+
element.tag_name == "textarea"
964+
and "\n" in text
965+
and "\r" not in text
966+
):
967+
text = text.replace("\n", "\r")
950968
element.send_keys(text)
951969
self.__slow_mode_pause_if_set()
952970
self.loop.run_until_complete(self.page.sleep(0.025))
@@ -1555,17 +1573,15 @@ def __install_pyautogui_if_missing(self):
15551573
import pyautogui
15561574
with suppress(Exception):
15571575
use_pyautogui_ver = constants.PyAutoGUI.VER
1558-
if pyautogui.__version__ != use_pyautogui_ver:
1559-
del pyautogui
1560-
shared_utils.pip_install(
1561-
"pyautogui", version=use_pyautogui_ver
1562-
)
1576+
u_pv = shared_utils.make_version_tuple(use_pyautogui_ver)
1577+
pv = shared_utils.make_version_tuple(pyautogui.__version__)
1578+
if pv < u_pv:
1579+
del pyautogui # To get newer ver
1580+
shared_utils.pip_install("pyautogui", version="Latest")
15631581
import pyautogui
15641582
except Exception:
15651583
print("\nPyAutoGUI required! Installing now...")
1566-
shared_utils.pip_install(
1567-
"pyautogui", version=constants.PyAutoGUI.VER
1568-
)
1584+
shared_utils.pip_install("pyautogui", version="Latest")
15691585
try:
15701586
import pyautogui
15711587
except Exception:

seleniumbase/fixtures/base_case.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ def __initialize_variables(self):
114114
self.driver = None
115115
self.environment = None
116116
self.env = None # Add a shortened version of self.environment
117-
self.version_list = [
118-
int(i) for i in __version__.split(".") if i.isdigit()
119-
]
117+
self.version_list = shared_utils.make_version_list(__version__)
120118
self.version_tuple = tuple(self.version_list)
121119
self.version_info = self.version_tuple
122120
self.time = time.time
@@ -14491,11 +14489,11 @@ def __activate_virtual_display(self):
1449114489
import pyautogui
1449214490
with suppress(Exception):
1449314491
use_pyautogui_ver = constants.PyAutoGUI.VER
14494-
if pyautogui.__version__ != use_pyautogui_ver:
14492+
u_pv = shared_utils.make_version_tuple(use_pyautogui_ver)
14493+
pv = shared_utils.make_version_tuple(pyautogui.__version__)
14494+
if pv < u_pv:
1449514495
del pyautogui # To get newer ver
14496-
shared_utils.pip_install(
14497-
"pyautogui", version=use_pyautogui_ver
14498-
)
14496+
shared_utils.pip_install("pyautogui", version="Latest")
1449914497
import pyautogui
1450014498
pyautogui_is_installed = True
1450114499
except Exception:
@@ -14504,9 +14502,7 @@ def __activate_virtual_display(self):
1450414502
"Installing now..."
1450514503
)
1450614504
print("\n" + message)
14507-
shared_utils.pip_install(
14508-
"pyautogui", version=constants.PyAutoGUI.VER
14509-
)
14505+
shared_utils.pip_install("pyautogui", version="Latest")
1451014506
import pyautogui
1451114507
pyautogui_is_installed = True
1451214508
if (

seleniumbase/fixtures/shared_utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,35 @@ def pip_install(package, version=None):
1818
pip_install_lock = fasteners.InterProcessLock(
1919
constants.PipInstall.LOCKFILE
2020
)
21+
upgrade_to_latest = False
22+
if (
23+
version
24+
and ("U" in str(version).upper() or "L" in str(version).upper())
25+
):
26+
# Upgrade to Latest when specified with "U" or "L"
27+
upgrade_to_latest = True
2128
with pip_install_lock:
2229
if not version:
2330
subprocess.check_call(
2431
[sys.executable, "-m", "pip", "install", package]
2532
)
26-
else:
33+
elif not upgrade_to_latest:
2734
package_and_version = package + "==" + str(version)
2835
subprocess.check_call(
2936
[sys.executable, "-m", "pip", "install", package_and_version]
3037
)
38+
else:
39+
subprocess.check_call(
40+
[sys.executable, "-m", "pip", "install", "-U", package]
41+
)
42+
43+
44+
def make_version_list(version_str):
45+
return [int(i) for i in version_str.split(".") if i.isdigit()]
46+
47+
48+
def make_version_tuple(version_str):
49+
return tuple(make_version_list(version_str))
3150

3251

3352
def get_mfa_code(totp_key=None):

seleniumbase/undetected/cdp_driver/cdp_util.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,26 @@ def __activate_virtual_display_as_needed(
121121
import pyautogui
122122
with suppress(Exception):
123123
use_pyautogui_ver = constants.PyAutoGUI.VER
124-
if pyautogui.__version__ != use_pyautogui_ver:
124+
u_pv = shared_utils.make_version_tuple(
125+
use_pyautogui_ver
126+
)
127+
pv = shared_utils.make_version_tuple(
128+
pyautogui.__version__
129+
)
130+
if pv < u_pv:
125131
del pyautogui # To get newer ver
126132
shared_utils.pip_install(
127-
"pyautogui", version=use_pyautogui_ver
133+
"pyautogui", version="Latest"
128134
)
129135
import pyautogui
130136
pyautogui_is_installed = True
131137
except Exception:
132138
message = (
133-
"PyAutoGUI is required for UC Mode on Linux! "
139+
"PyAutoGUI is required for CDP Mode on Linux! "
134140
"Installing now..."
135141
)
136142
print("\n" + message)
137-
shared_utils.pip_install(
138-
"pyautogui", version=constants.PyAutoGUI.VER
139-
)
143+
shared_utils.pip_install("pyautogui", version="Latest")
140144
import pyautogui
141145
pyautogui_is_installed = True
142146
if (

0 commit comments

Comments
 (0)