Skip to content

Commit c722f8f

Browse files
authored
Merge pull request #1978 from seleniumbase/refactoring-and-uc-mode-updates
Selenium upgrade, and more
2 parents c70e8b2 + 30e42c6 commit c722f8f

File tree

10 files changed

+58
-36
lines changed

10 files changed

+58
-36
lines changed

examples/coffee_cart_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_coffee_promo_with_preview(self, accept_promo):
4545
else:
4646
self.click("div.promo button.no")
4747
checkout_button = 'button[data-test="checkout"]'
48-
if promo:
48+
if promo and not self.browser == "safari":
4949
self.hover(checkout_button)
5050
if not self.is_element_visible("ul.cart-preview"):
5151
self.highlight(checkout_button)

examples/test_hack_search.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def test_hack_search(self):
1313
print("\n This test is not for Headless Mode.")
1414
self.skip('Do not use "--headless" with this test.')
1515
self.open("https://google.com/ncr")
16+
self.hide_elements("iframe")
1617
self.assert_element('[title="Search"]')
1718
self.sleep(0.5)
1819
self.set_attribute('[action="/search"]', "action", "//bing.com/search")
@@ -24,7 +25,7 @@ def test_hack_search(self):
2425
self.highlight_click('[href*="github.com/seleniumbase/SeleniumBase"]')
2526
self.highlight_click('[href="/seleniumbase/SeleniumBase"]')
2627
self.highlight_click('a[title="examples"]')
27-
self.assert_text("examples", "strong.final-path")
28-
self.highlight_click('a[title="test_hack_search.py"]')
29-
self.assert_text("test_hack_search.py", "strong.final-path")
30-
self.highlight("strong.final-path")
28+
self.assert_text("examples", "#file-name-id")
29+
self.highlight_click('div[title="test_hack_search.py"] a')
30+
self.assert_text("test_hack_search.py", "#file-name-id")
31+
self.highlight("#file-name-id")

examples/wordle_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def test_wordle(self):
5454
self.open_if_not_url("about:blank")
5555
self.skip("Skip this test in headless mode!")
5656
self.open("https://www.nytimes.com/games/wordle/index.html")
57+
self.click_if_visible("button.purr-blocker-card__button", timeout=2)
5758
self.click_if_visible('button:contains("Play")', timeout=2)
5859
self.click_if_visible('svg[data-testid="icon-close"]', timeout=2)
5960
self.remove_elements("div.place-ad")

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ parse-type>=0.6.2
1818
six==1.16.0
1919
idna==3.4
2020
chardet==4.0.0;python_version<"3.7"
21-
chardet==5.1.0;python_version>="3.7"
21+
chardet==5.2.0;python_version>="3.7"
2222
charset-normalizer==2.0.12;python_version<"3.7"
2323
charset-normalizer==3.2.0;python_version>="3.7"
2424
urllib3==1.26.12;python_version<"3.7"
@@ -34,7 +34,7 @@ trio==0.22.2;python_version>="3.7"
3434
trio-websocket==0.10.3;python_version>="3.7"
3535
wsproto==1.2.0;python_version>="3.7"
3636
selenium==3.141.0;python_version<"3.7"
37-
selenium==4.10.0;python_version>="3.7"
37+
selenium==4.11.2;python_version>="3.7"
3838
msedge-selenium-tools==3.141.3;python_version<"3.7"
3939
cssselect==1.1.0;python_version<"3.7"
4040
cssselect==1.2.0;python_version>="3.7"
@@ -83,7 +83,7 @@ commonmark==0.9.1;python_version<"3.7"
8383
markdown-it-py==3.0.0;python_version>="3.8"
8484
mdurl==0.1.2;python_version>="3.7"
8585
rich==12.6.0;python_version<"3.7"
86-
rich==13.5.1;python_version>="3.7"
86+
rich==13.5.2;python_version>="3.7"
8787

8888
# --- Testing Requirements --- #
8989
# ("pip install -r requirements.txt" also installs this, but "pip install -e ." won't.)

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.16.4"
2+
__version__ = "4.17.0"

seleniumbase/core/browser_launcher.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ def uc_special_open_if_cf(driver, url):
183183
and has_cf(requests_get(url).text)
184184
):
185185
with driver:
186+
time.sleep(0.25)
186187
driver.execute_script('window.open("%s","_blank");' % url)
187-
driver.reconnect(0.555)
188-
driver.close()
189-
driver.switch_to.window(driver.window_handles[-1])
188+
driver.close()
189+
driver.switch_to.window(driver.window_handles[-1])
190+
time.sleep(0.11)
190191
else:
191192
driver.open(url) # The original one
192193
return None
@@ -195,8 +196,9 @@ def uc_special_open_if_cf(driver, url):
195196
def uc_open(driver, url):
196197
if (url.startswith("http:") or url.startswith("https:")):
197198
with driver:
198-
driver.open(url)
199199
time.sleep(0.25)
200+
driver.open(url)
201+
time.sleep(0.11)
200202
else:
201203
driver.open(url) # The original one
202204
return None
@@ -205,10 +207,11 @@ def uc_open(driver, url):
205207
def uc_open_with_tab(driver, url):
206208
if (url.startswith("http:") or url.startswith("https:")):
207209
with driver:
210+
time.sleep(0.25)
208211
driver.execute_script('window.open("%s","_blank");' % url)
209212
driver.close()
210213
driver.switch_to.window(driver.window_handles[-1])
211-
time.sleep(0.25)
214+
time.sleep(0.11)
212215
else:
213216
driver.open(url) # The original one
214217
return None
@@ -849,6 +852,10 @@ def _set_chrome_options(
849852
if headless or headless2 or is_using_uc(undetectable, browser_name):
850853
chrome_options.add_argument("--disable-renderer-backgrounding")
851854
chrome_options.add_argument("--disable-backgrounding-occluded-windows")
855+
chrome_options.add_argument(
856+
'--disable-features=OptimizationHintsFetching,'
857+
'OptimizationTargetPrediction'
858+
)
852859
if (
853860
is_using_uc(undetectable, browser_name)
854861
and (
@@ -870,10 +877,6 @@ def _set_chrome_options(
870877
chrome_options.add_argument(
871878
"--disable-autofill-keyboard-accessory-view[8]"
872879
)
873-
chrome_options.add_argument(
874-
'--disable-features=OptimizationHintsFetching,'
875-
'OptimizationTargetPrediction'
876-
)
877880
chrome_options.add_argument("--homepage=about:blank")
878881
chrome_options.add_argument("--dom-automation")
879882
chrome_options.add_argument("--disable-hang-monitor")
@@ -2033,7 +2036,7 @@ def get_local_driver(
20332036
if selenium4_or_newer:
20342037
service = FirefoxService(
20352038
executable_path=LOCAL_GECKODRIVER,
2036-
log_path=os.devnull,
2039+
log_output=os.devnull,
20372040
)
20382041
try:
20392042
return webdriver.Firefox(
@@ -2079,7 +2082,7 @@ def get_local_driver(
20792082
)
20802083
else:
20812084
if selenium4_or_newer:
2082-
service = FirefoxService(log_path=os.devnull)
2085+
service = FirefoxService(log_output=os.devnull)
20832086
try:
20842087
return webdriver.Firefox(
20852088
service=service,
@@ -2539,7 +2542,7 @@ def get_local_driver(
25392542
try:
25402543
service = EdgeService(
25412544
executable_path=LOCAL_EDGEDRIVER,
2542-
log_path=os.devnull,
2545+
log_output=os.devnull,
25432546
service_args=["--disable-build-check"],
25442547
)
25452548
driver = Edge(service=service, options=edge_options)
@@ -2565,7 +2568,7 @@ def get_local_driver(
25652568
elif "DevToolsActivePort file doesn't exist" in e.msg:
25662569
service = EdgeService(
25672570
executable_path=LOCAL_EDGEDRIVER,
2568-
log_path=os.devnull,
2571+
log_output=os.devnull,
25692572
service_args=["--disable-build-check"],
25702573
)
25712574
# https://stackoverflow.com/a/56638103/7058266
@@ -2603,7 +2606,7 @@ def get_local_driver(
26032606
pass
26042607
service = EdgeService(
26052608
executable_path=LOCAL_EDGEDRIVER,
2606-
log_path=os.devnull,
2609+
log_output=os.devnull,
26072610
service_args=["--disable-build-check"],
26082611
)
26092612
driver = Edge(service=service, options=edge_options)
@@ -2639,7 +2642,7 @@ def get_local_driver(
26392642
elif "DevToolsActivePort file doesn't exist" in e.msg:
26402643
service = EdgeService(
26412644
executable_path=LOCAL_EDGEDRIVER,
2642-
log_path=os.devnull,
2645+
log_output=os.devnull,
26432646
service_args=["--disable-build-check"],
26442647
)
26452648
# https://stackoverflow.com/a/56638103/7058266
@@ -3184,7 +3187,7 @@ def get_local_driver(
31843187
else:
31853188
service = ChromeService(
31863189
executable_path=LOCAL_CHROMEDRIVER,
3187-
log_path=os.devnull,
3190+
log_output=os.devnull,
31883191
service_args=service_args,
31893192
)
31903193
driver = webdriver.Chrome(
@@ -3201,7 +3204,7 @@ def get_local_driver(
32013204
else:
32023205
if selenium4_or_newer:
32033206
service = ChromeService(
3204-
log_path=os.devnull,
3207+
log_output=os.devnull,
32053208
service_args=service_args,
32063209
)
32073210
driver = webdriver.Chrome(
@@ -3225,7 +3228,7 @@ def get_local_driver(
32253228
elif "Missing or invalid capabilities" in e.msg:
32263229
if selenium4_or_newer:
32273230
chrome_options.add_experimental_option("w3c", True)
3228-
service = ChromeService(log_path=os.devnull)
3231+
service = ChromeService(log_output=os.devnull)
32293232
with warnings.catch_warnings():
32303233
warnings.simplefilter(
32313234
"ignore", category=DeprecationWarning
@@ -3372,7 +3375,7 @@ def get_local_driver(
33723375
elif "Missing or invalid capabilities" in e.msg:
33733376
if selenium4_or_newer:
33743377
chrome_options.add_experimental_option("w3c", True)
3375-
service = ChromeService(log_path=os.devnull)
3378+
service = ChromeService(log_output=os.devnull)
33763379
with warnings.catch_warnings():
33773380
warnings.simplefilter(
33783381
"ignore", category=DeprecationWarning

seleniumbase/fixtures/base_case.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ def click(
412412
and (self.browser == "ie" or self.browser == "safari")
413413
):
414414
self.__jquery_click(selector, by=by)
415+
elif self.browser == "safari":
416+
self.execute_script("arguments[0].click();", element)
415417
else:
416418
href = None
417419
new_tab = False
@@ -458,6 +460,8 @@ def click(
458460
pass
459461
if self.browser == "safari" and by == By.LINK_TEXT:
460462
self.__jquery_click(selector, by=by)
463+
elif self.browser == "safari":
464+
self.execute_script("arguments[0].click();", element)
461465
else:
462466
self.__element_click(element)
463467
except ENI_Exception as e:
@@ -2076,7 +2080,10 @@ def click_visible_elements(
20762080
try:
20772081
if element.is_displayed():
20782082
self.__scroll_to_element(element)
2079-
element.click()
2083+
if self.browser == "safari":
2084+
self.execute_script("arguments[0].click();", element)
2085+
else:
2086+
element.click()
20802087
click_count += 1
20812088
self.wait_for_ready_state_complete()
20822089
except ECI_Exception:
@@ -2087,7 +2094,12 @@ def click_visible_elements(
20872094
try:
20882095
if element.is_displayed():
20892096
self.__scroll_to_element(element)
2090-
element.click()
2097+
if self.browser == "safari":
2098+
self.execute_script(
2099+
"arguments[0].click();", element
2100+
)
2101+
else:
2102+
element.click()
20912103
click_count += 1
20922104
self.wait_for_ready_state_complete()
20932105
except (Stale_Exception, ENI_Exception):

seleniumbase/undetected/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,14 @@ def __init__(
289289
executable_path=self.patcher.executable_path,
290290
service_args=["--disable-build-check"],
291291
port=port,
292-
log_path=os.devnull,
292+
log_output=os.devnull,
293293
)
294294
else:
295295
service_ = selenium.webdriver.chrome.service.Service(
296296
executable_path=driver_executable_path,
297297
service_args=["--disable-build-check"],
298298
port=port,
299-
log_path=os.devnull,
299+
log_output=os.devnull,
300300
)
301301
if hasattr(service_, "creationflags"):
302302
setattr(service_, "creationflags", creationflags)

seleniumbase/undetected/patcher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ def gen_call_function_js_cache_name(match):
208208
gen_js_whitespaces,
209209
file_bin,
210210
)
211+
file_bin = re.sub(
212+
b"window\\.cdc_[a-zA-Z0-9]{22}_(Array|Promise|Symbol)",
213+
b"window\\.ccd_adoQpoasnaf67pfcZLmcfl_(Array|Promise|Symbol)",
214+
file_bin,
215+
)
211216
file_bin = re.sub(
212217
b"'\\$cdc_[a-zA-Z0-9]{22}_';",
213218
gen_call_function_js_cache_name,

setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
print("\nERROR! Publishing to PyPI requires Python>=3.9")
3535
sys.exit()
3636
print("\n*** Checking code health with flake8:\n")
37-
os.system("python -m pip install 'flake8==6.0.0'")
37+
os.system("python -m pip install 'flake8==6.1.0'")
3838
flake8_status = os.system("flake8 --exclude=recordings,temp")
3939
if flake8_status != 0:
4040
print("\nERROR! Fix flake8 issues before publishing to PyPI!\n")
@@ -152,7 +152,7 @@
152152
"six==1.16.0",
153153
"idna==3.4",
154154
'chardet==4.0.0;python_version<"3.7"',
155-
'chardet==5.1.0;python_version>="3.7"',
155+
'chardet==5.2.0;python_version>="3.7"',
156156
'charset-normalizer==2.0.12;python_version<"3.7"',
157157
'charset-normalizer==3.2.0;python_version>="3.7"',
158158
'urllib3==1.26.12;python_version<"3.7"',
@@ -168,7 +168,7 @@
168168
'trio-websocket==0.10.3;python_version>="3.7"',
169169
'wsproto==1.2.0;python_version>="3.7"',
170170
'selenium==3.141.0;python_version<"3.7"',
171-
'selenium==4.10.0;python_version>="3.7"',
171+
'selenium==4.11.2;python_version>="3.7"',
172172
'msedge-selenium-tools==3.141.3;python_version<"3.7"',
173173
'cssselect==1.1.0;python_version<"3.7"',
174174
'cssselect==1.2.0;python_version>="3.7"',
@@ -217,7 +217,7 @@
217217
'markdown-it-py==3.0.0;python_version>="3.8"', # For new "rich"
218218
'mdurl==0.1.2;python_version>="3.7"', # For new "rich"
219219
'rich==12.6.0;python_version<"3.7"',
220-
'rich==13.5.1;python_version>="3.7"',
220+
'rich==13.5.2;python_version>="3.7"',
221221
],
222222
extras_require={
223223
# pip install -e .[allure]

0 commit comments

Comments
 (0)