Skip to content

Commit 1fc2204

Browse files
authored
Merge pull request #1372 from seleniumbase/selenium-upgrade
Selenium upgrade
2 parents e0f94c8 + b289296 commit 1fc2204

File tree

6 files changed

+82
-30
lines changed

6 files changed

+82
-30
lines changed

examples/test_canvas.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ def get_pixel_colors(self):
1818
else:
1919
return [color["0"], color["1"], color["2"]]
2020

21-
def test_canvas_actions(self):
21+
def test_canvas_click_from_center(self):
22+
self.open("https://seleniumbase.io/other/canvas")
23+
self.click_with_offset("canvas", 0, 0, center=True)
24+
self.sleep(1) # Not needed (Lets you see the alert pop up)
25+
alert = self.switch_to_alert()
26+
self.assert_equal(alert.text, "You clicked on the square!")
27+
self.accept_alert()
28+
self.sleep(1) # Not needed (Lets you see the alert go away)
29+
30+
def test_click_with_offset(self):
2231
self.open("https://seleniumbase.io/canvas/")
2332
self.highlight("canvas")
2433
rgb = self.get_pixel_colors()
@@ -27,12 +36,3 @@ def test_canvas_actions(self):
2736
self.highlight("canvas", loops=5)
2837
rgb = self.get_pixel_colors()
2938
self.assert_equal(rgb, [39, 42, 56]) # Blue by hamburger
30-
31-
def test_canvas_click(self):
32-
self.open("https://seleniumbase.io/other/canvas")
33-
self.click_with_offset("canvas", 300, 200)
34-
self.sleep(1) # Not needed (Lets you see the alert pop up)
35-
alert = self.switch_to_alert()
36-
self.assert_equal(alert.text, "You clicked on the square!")
37-
self.accept_alert()
38-
self.sleep(1) # Not needed (Lets you see the alert go away)

help_docs/method_summary.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ self.click_if_visible(selector, by="css selector")
129129
self.click_active_element()
130130

131131
self.click_with_offset(
132-
selector, x, y, by="css selector", mark=None, timeout=None)
132+
selector, x, y, by="css selector", mark=None, timeout=None, center=None)
133133

134134
self.double_click_with_offset(
135-
selector, x, y, by="css selector", mark=None, timeout=None)
135+
selector, x, y, by="css selector", mark=None, timeout=None, center=None)
136136

137137
self.is_selected(selector, by="css selector", timeout=None)
138138
# Duplicates: self.is_checked(selector, by="css selector", timeout=None)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ trio-websocket==0.9.2;python_version>="3.7"
4949
pyopenssl==22.0.0;python_version>="3.7"
5050
wsproto==1.1.0;python_version>="3.7"
5151
selenium==3.141.0;python_version<"3.7"
52-
selenium==4.2.0;python_version>="3.7"
52+
selenium==4.3.0;python_version>="3.7"
5353
msedge-selenium-tools==3.141.3;python_version<"3.7"
5454
more-itertools==5.0.0;python_version<"3.5"
5555
more-itertools==8.13.0;python_version>="3.5"

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__ = "3.2.12"
2+
__version__ = "3.3.0"

seleniumbase/fixtures/base_case.py

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ def test_anything(self):
7878
python3 = False
7979
reload(sys) # noqa: F821
8080
sys.setdefaultencoding("utf8")
81-
selenium4 = False
81+
selenium4_or_newer = False
8282
if sys.version_info >= (3, 7):
83-
selenium4 = True
83+
selenium4_or_newer = True
8484

8585

8686
class BaseCase(unittest.TestCase):
@@ -1782,31 +1782,61 @@ def click_active_element(self):
17821782
self.__slow_mode_pause_if_active()
17831783

17841784
def click_with_offset(
1785-
self, selector, x, y, by="css selector", mark=None, timeout=None
1785+
self,
1786+
selector,
1787+
x,
1788+
y,
1789+
by="css selector",
1790+
mark=None,
1791+
timeout=None,
1792+
center=None,
17861793
):
17871794
"""
17881795
Click an element at an {X,Y}-offset location.
17891796
{0,0} is the top-left corner of the element.
1797+
If center==True, {0,0} becomes the center of the element.
17901798
If mark==True, will draw a dot at location. (Useful for debugging)
17911799
In Demo Mode, mark becomes True unless set to False. (Default: None)
17921800
"""
17931801
self.__check_scope()
17941802
self.__click_with_offset(
1795-
selector, x, y, by=by, double=False, mark=mark, timeout=timeout
1803+
selector,
1804+
x,
1805+
y,
1806+
by=by,
1807+
double=False,
1808+
mark=mark,
1809+
timeout=timeout,
1810+
center=center,
17961811
)
17971812

17981813
def double_click_with_offset(
1799-
self, selector, x, y, by="css selector", mark=None, timeout=None
1814+
self,
1815+
selector,
1816+
x,
1817+
y,
1818+
by="css selector",
1819+
mark=None,
1820+
timeout=None,
1821+
center=None,
18001822
):
18011823
"""
18021824
Double click an element at an {X,Y}-offset location.
18031825
{0,0} is the top-left corner of the element.
1826+
If center==True, {0,0} becomes the center of the element.
18041827
If mark==True, will draw a dot at location. (Useful for debugging)
18051828
In Demo Mode, mark becomes True unless set to False. (Default: None)
18061829
"""
18071830
self.__check_scope()
18081831
self.__click_with_offset(
1809-
selector, x, y, by=by, double=True, mark=mark, timeout=timeout
1832+
selector,
1833+
x,
1834+
y,
1835+
by=by,
1836+
double=True,
1837+
mark=mark,
1838+
timeout=timeout,
1839+
center=center,
18101840
)
18111841

18121842
def is_checked(self, selector, by="css selector", timeout=None):
@@ -6492,7 +6522,7 @@ def __get_shadow_element(
64926522
for selector_part in selectors[1:]:
64936523
shadow_root = None
64946524
if (
6495-
selenium4
6525+
selenium4_or_newer
64966526
and self.is_chromium()
64976527
and int(self.__get_major_browser_version()) >= 96
64986528
):
@@ -6562,7 +6592,7 @@ def __get_shadow_element(
65626592
selector_chain += selector_part
65636593
try:
65646594
if (
6565-
selenium4
6595+
selenium4_or_newer
65666596
and self.is_chromium()
65676597
and int(self.__get_major_browser_version()) >= 96
65686598
):
@@ -11382,6 +11412,7 @@ def __click_with_offset(
1138211412
double=False,
1138311413
mark=None,
1138411414
timeout=None,
11415+
center=None,
1138511416
):
1138611417
from selenium.webdriver.common.action_chains import ActionChains
1138711418

@@ -11406,8 +11437,16 @@ def __click_with_offset(
1140611437
selector = self.convert_to_css_selector(selector, by=by)
1140711438
selector = re.escape(selector)
1140811439
selector = self.__escape_quotes_if_needed(selector)
11409-
px = x - 3
11410-
py = y - 3
11440+
m_x = x
11441+
m_y = y
11442+
if center:
11443+
element_rect = element.rect
11444+
left_offset = element_rect['width'] / 2
11445+
top_offset = element_rect['height'] / 2
11446+
m_x = left_offset + (m_x or 0)
11447+
m_y = top_offset + (m_y or 0)
11448+
px = m_x - 3
11449+
py = m_y - 3
1141111450
script = (
1141211451
"var canvas = document.querySelector('%s');"
1141311452
"var ctx = canvas.getContext('2d');"
@@ -11428,12 +11467,25 @@ def __click_with_offset(
1142811467
except Exception:
1142911468
pass
1143011469
try:
11470+
if selenium4_or_newer and not center:
11471+
element_rect = element.rect
11472+
left_offset = element_rect['width'] / 2
11473+
top_offset = element_rect['height'] / 2
11474+
x = -left_offset + (x or 0)
11475+
y = -top_offset + (y or 0)
11476+
elif selenium4_or_newer and center:
11477+
pass
11478+
elif not selenium4_or_newer and not center:
11479+
pass
11480+
else:
11481+
# not selenium4_or_newer and center:
11482+
element_rect = element.rect
11483+
left_offset = element_rect['width'] / 2
11484+
top_offset = element_rect['height'] / 2
11485+
x = left_offset + x
11486+
y = top_offset + y
1143111487
action_chains = ActionChains(self.driver)
11432-
import warnings
11433-
11434-
with warnings.catch_warnings():
11435-
warnings.simplefilter("ignore", category=DeprecationWarning)
11436-
action_chains.move_to_element_with_offset(element, x, y)
11488+
action_chains.move_to_element_with_offset(element, x, y)
1143711489
if not double:
1143811490
action_chains.click().perform()
1143911491
else:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
'pyopenssl==22.0.0;python_version>="3.7"',
175175
'wsproto==1.1.0;python_version>="3.7"',
176176
'selenium==3.141.0;python_version<"3.7"',
177-
'selenium==4.2.0;python_version>="3.7"',
177+
'selenium==4.3.0;python_version>="3.7"',
178178
'msedge-selenium-tools==3.141.3;python_version<"3.7"',
179179
'more-itertools==5.0.0;python_version<"3.5"',
180180
'more-itertools==8.13.0;python_version>="3.5"',

0 commit comments

Comments
 (0)