Skip to content

Commit fbd5f80

Browse files
committed
Add an arg to decide if methods should scroll automatically
1 parent 16c6103 commit fbd5f80

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ def get(self, url):
159159
else:
160160
return self.get_element(url) # url is treated like a selector
161161

162-
def click(self, selector, by=By.CSS_SELECTOR, timeout=None, delay=0):
162+
def click(
163+
self, selector, by=By.CSS_SELECTOR, timeout=None, delay=0, scroll=True
164+
):
163165
self.__check_scope()
164166
if not timeout:
165167
timeout = settings.SMALL_TIMEOUT
@@ -190,7 +192,7 @@ def click(self, selector, by=By.CSS_SELECTOR, timeout=None, delay=0):
190192
self.driver, selector, by, timeout=timeout
191193
)
192194
self.__demo_mode_highlight_if_active(original_selector, original_by)
193-
if not self.demo_mode and not self.slow_mode:
195+
if scroll and not self.demo_mode and not self.slow_mode:
194196
self.__scroll_to_element(element, selector, by)
195197
pre_action_url = self.driver.current_url
196198
try:
@@ -1184,7 +1186,13 @@ def get_attribute(
11841186
return None
11851187

11861188
def set_attribute(
1187-
self, selector, attribute, value, by=By.CSS_SELECTOR, timeout=None
1189+
self,
1190+
selector,
1191+
attribute,
1192+
value,
1193+
by=By.CSS_SELECTOR,
1194+
timeout=None,
1195+
scroll=False,
11881196
):
11891197
"""This method uses JavaScript to set/update an attribute.
11901198
Only the first matching selector from querySelector() is used."""
@@ -1194,7 +1202,7 @@ def set_attribute(
11941202
if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT:
11951203
timeout = self.__get_new_timeout(timeout)
11961204
selector, by = self.__recalculate_selector(selector, by)
1197-
if self.is_element_visible(selector, by=by):
1205+
if scroll and self.is_element_visible(selector, by=by):
11981206
try:
11991207
self.scroll_to(selector, by=by, timeout=timeout)
12001208
except Exception:
@@ -3045,10 +3053,13 @@ def click_xpath(self, xpath):
30453053
# so self.click_xpath() is just a longer name for the same action.
30463054
self.click(xpath, by=By.XPATH)
30473055

3048-
def js_click(self, selector, by=By.CSS_SELECTOR, all_matches=False):
3056+
def js_click(
3057+
self, selector, by=By.CSS_SELECTOR, all_matches=False, scroll=True
3058+
):
30493059
"""Clicks an element using JavaScript.
30503060
Can be used to click hidden / invisible elements.
3051-
If "all_matches" is False, only the first match is clicked."""
3061+
If "all_matches" is False, only the first match is clicked.
3062+
If "scroll" is False, won't scroll unless running in Demo Mode."""
30523063
self.wait_for_ready_state_complete()
30533064
selector, by = self.__recalculate_selector(selector, by, xp_ok=False)
30543065
if by == By.LINK_TEXT:
@@ -3066,7 +3077,7 @@ def js_click(self, selector, by=By.CSS_SELECTOR, all_matches=False):
30663077
)
30673078
if self.is_element_visible(selector, by=by):
30683079
self.__demo_mode_highlight_if_active(selector, by)
3069-
if not self.demo_mode and not self.slow_mode:
3080+
if scroll and not self.demo_mode and not self.slow_mode:
30703081
success = js_utils.scroll_to_element(self.driver, element)
30713082
if not success:
30723083
self.wait_for_ready_state_complete()
@@ -4133,7 +4144,9 @@ def convert_to_css_selector(self, selector, by):
41334144
% (selector, by)
41344145
)
41354146

4136-
def set_value(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
4147+
def set_value(
4148+
self, selector, text, by=By.CSS_SELECTOR, timeout=None, scroll=True
4149+
):
41374150
""" This method uses JavaScript to update a text field. """
41384151
self.__check_scope()
41394152
if not timeout:
@@ -4146,7 +4159,7 @@ def set_value(self, selector, text, by=By.CSS_SELECTOR, timeout=None):
41464159
orginal_selector = selector
41474160
css_selector = self.convert_to_css_selector(selector, by=by)
41484161
self.__demo_mode_highlight_if_active(orginal_selector, by)
4149-
if not self.demo_mode and not self.slow_mode:
4162+
if scroll and not self.demo_mode and not self.slow_mode:
41504163
self.scroll_to(orginal_selector, by=by, timeout=timeout)
41514164
if type(text) is int or type(text) is float:
41524165
text = str(text)

0 commit comments

Comments
 (0)