Skip to content

Commit 2a35c26

Browse files
committed
Update URL detection
1 parent 1776870 commit 2a35c26

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4543,8 +4543,14 @@ def __recalculate_selector(self, selector, by):
45434543
return (selector, by)
45444544

45454545
def __looks_like_a_page_url(self, url):
4546-
if (url.startswith("http://") or url.startswith("https://") or (
4547-
url.startswith("://") or page_utils.is_valid_url(url))):
4546+
""" Returns True if the url parameter looks like a URL. This method
4547+
is slightly more lenient than page_utils.is_valid_url(url) due to
4548+
possible typos when calling self.get(url), which will try to
4549+
navigate to the page if a URL is detected, but will instead call
4550+
self.get_element(URL_AS_A_SELECTOR) if the input in not a URL. """
4551+
if (url.startswith("http:") or url.startswith("https:") or (
4552+
url.startswith("://") or url.startswith("data:") or (
4553+
url.startswith("about:") or url.startswith("chrome:")))):
45484554
return True
45494555
else:
45504556
return False

seleniumbase/fixtures/page_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def is_valid_url(url):
106106
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
107107
r'(?::\d+)?' # optional port
108108
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
109-
if regex.match(url) or url == 'about:blank' or url == 'data:,':
109+
if regex.match(url) or ((url.startswith('about:') or (
110+
url.startswith('data:') or url.startswith('chrome:')))
111+
and " " not in url):
110112
return True
111113
else:
112114
return False

0 commit comments

Comments
 (0)