Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d7a6152

Browse files
committed
Unify "index" type of keyword arguments.
create_webdriver was marked as returning a str, however, its return value is coming from register_driver which is documented to return int. These where changed to return actual int. switch_driver was only accepting str as "index_or_alias". While aliases are str's since create_driver now returns the actual index as int, accepting both types makes more sense. select and unselect list keywords where typehinted to receive only str as index type - when called from python side, this does not make much sense so changed those to int as RF should do type conversion automatically. Fixes #1791
1 parent 64d878a commit d7a6152

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/SeleniumLibrary/__init__.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class SeleniumLibrary:
133133
def select_all_from_list(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
134134
def select_checkbox(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
135135
def select_frame(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
136-
def select_from_list_by_index(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *indexes: str): ...
136+
def select_from_list_by_index(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *indexes: int): ...
137137
def select_from_list_by_label(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *labels: str): ...
138138
def select_from_list_by_value(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *values: str): ...
139139
def select_radio_button(self, group_name: str, value: str): ...
@@ -147,7 +147,7 @@ class SeleniumLibrary:
147147
def set_window_size(self, width: int, height: int, inner: bool = False): ...
148148
def simulate_event(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], event: str): ...
149149
def submit_form(self, locator: Optional[Union[selenium.webdriver.remote.webelement.WebElement, None, str]] = None): ...
150-
def switch_browser(self, index_or_alias: str): ...
150+
def switch_browser(self, index_or_alias: Union[str, int]): ...
151151
def switch_window(self, locator: Union[list, str] = 'MAIN', timeout: Optional[Union[str, None]] = None, browser: str = 'CURRENT'): ...
152152
def table_cell_should_contain(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, None, str], row: int, column: int, expected: str, loglevel: str = 'TRACE'): ...
153153
def table_column_should_contain(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, None, str], column: int, expected: str, loglevel: str = 'TRACE'): ...
@@ -163,7 +163,7 @@ class SeleniumLibrary:
163163
def unselect_all_from_list(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
164164
def unselect_checkbox(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str]): ...
165165
def unselect_frame(self): ...
166-
def unselect_from_list_by_index(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *indexes: str): ...
166+
def unselect_from_list_by_index(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *indexes: int): ...
167167
def unselect_from_list_by_label(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *labels: str): ...
168168
def unselect_from_list_by_value(self, locator: Union[selenium.webdriver.remote.webelement.WebElement, str], *values: str): ...
169169
def wait_for_condition(self, condition: str, timeout: Optional[Union[datetime.timedelta, None]] = None, error: Optional[Union[str, None]] = None): ...

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def _make_new_browser(
344344
@keyword
345345
def create_webdriver(
346346
self, driver_name: str, alias: Optional[str] = None, kwargs={}, **init_kwargs
347-
) -> str:
347+
) -> int:
348348
"""Creates an instance of Selenium WebDriver.
349349
350350
Like `Open Browser`, but allows passing arguments to the created
@@ -400,7 +400,7 @@ def _wrap_event_firing_webdriver(self, driver):
400400
return EventFiringWebDriver(driver, self.ctx.event_firing_webdriver())
401401

402402
@keyword
403-
def switch_browser(self, index_or_alias: str):
403+
def switch_browser(self, index_or_alias: Union[str, int]):
404404
"""Switches between active browsers using ``index_or_alias``.
405405
406406
Indices are returned by the `Open Browser` keyword and aliases can

src/SeleniumLibrary/keywords/selectelement.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def select_all_from_list(self, locator: Union[WebElement, str]):
206206
select.select_by_index(index)
207207

208208
@keyword
209-
def select_from_list_by_index(self, locator: Union[WebElement, str], *indexes: str):
209+
def select_from_list_by_index(self, locator: Union[WebElement, str], *indexes: int):
210210
"""Selects options from selection list ``locator`` by ``indexes``.
211211
212212
Indexes of list options start from 0.
@@ -228,7 +228,7 @@ def select_from_list_by_index(self, locator: Union[WebElement, str], *indexes: s
228228
)
229229
select = self._get_select_list(locator)
230230
for index in indexes:
231-
select.select_by_index(int(index))
231+
select.select_by_index(index)
232232

233233
@keyword
234234
def select_from_list_by_value(self, locator: Union[WebElement, str], *values: str):
@@ -293,7 +293,7 @@ def unselect_all_from_list(self, locator: Union[WebElement, str]):
293293

294294
@keyword
295295
def unselect_from_list_by_index(
296-
self, locator: Union[WebElement, str], *indexes: str
296+
self, locator: Union[WebElement, str], *indexes: int
297297
):
298298
"""Unselects options from selection list ``locator`` by ``indexes``.
299299
@@ -316,7 +316,7 @@ def unselect_from_list_by_index(
316316
"Un-selecting options works only with multi-selection lists."
317317
)
318318
for index in indexes:
319-
select.deselect_by_index(int(index))
319+
select.deselect_by_index(index)
320320

321321
@keyword
322322
def unselect_from_list_by_value(

0 commit comments

Comments
 (0)