1616
1717import time
1818import types
19+ from typing import Optional , Union , Any , List
1920
2021from selenium import webdriver
2122from selenium .webdriver .support .event_firing_webdriver import EventFiringWebDriver
@@ -56,16 +57,16 @@ def close_browser(self):
5657 @keyword
5758 def open_browser (
5859 self ,
59- url = None ,
60- browser = "firefox" ,
61- alias = None ,
62- remote_url = False ,
63- desired_capabilities = None ,
64- ff_profile_dir = None ,
65- options = None ,
66- service_log_path = None ,
67- executable_path = None ,
68- ):
60+ url : Optional [ str ] = None ,
61+ browser : str = "firefox" ,
62+ alias : Optional [ str ] = None ,
63+ remote_url : Optional [ str ] = False ,
64+ desired_capabilities : Union [ str , dict , None ] = None ,
65+ ff_profile_dir : Optional [ str ] = None ,
66+ options : Any = None ,
67+ service_log_path : Optional [ str ] = None ,
68+ executable_path : Optional [ str ] = None ,
69+ ) -> str :
6970 """Opens a new browser instance to the optional ``url``.
7071
7172 The ``browser`` argument specifies which browser to use. The
@@ -341,7 +342,7 @@ def _make_new_browser(
341342 return index
342343
343344 @keyword
344- def create_webdriver (self , driver_name , alias = None , kwargs = {}, ** init_kwargs ):
345+ def create_webdriver (self , driver_name : str , alias : Optional [ str ] = None , kwargs = {}, ** init_kwargs ) -> str :
345346 """Creates an instance of Selenium WebDriver.
346347
347348 Like `Open Browser`, but allows passing arguments to the created
@@ -397,7 +398,7 @@ def _wrap_event_firing_webdriver(self, driver):
397398 return EventFiringWebDriver (driver , self .ctx .event_firing_webdriver ())
398399
399400 @keyword
400- def switch_browser (self , index_or_alias ):
401+ def switch_browser (self , index_or_alias : str ):
401402 """Switches between active browsers using ``index_or_alias``.
402403
403404 Indices are returned by the `Open Browser` keyword and aliases can
@@ -434,7 +435,7 @@ def switch_browser(self, index_or_alias):
434435 )
435436
436437 @keyword
437- def get_browser_ids (self ):
438+ def get_browser_ids (self ) -> List [ str ] :
438439 """Returns index of all active browser as list.
439440
440441 Example:
@@ -451,7 +452,7 @@ def get_browser_ids(self):
451452 return self .drivers .active_driver_ids
452453
453454 @keyword
454- def get_browser_aliases (self ):
455+ def get_browser_aliases (self ) -> List [ str ] :
455456 """Returns aliases of all active browser that has an alias as NormalizedDict.
456457 The dictionary contains the aliases as keys and the index as value.
457458 This can be accessed as dictionary ``${aliases.key}`` or as list ``@{aliases}[0]``.
@@ -472,30 +473,30 @@ def get_browser_aliases(self):
472473 return self .drivers .active_aliases
473474
474475 @keyword
475- def get_session_id (self ):
476+ def get_session_id (self ) -> str :
476477 """Returns the currently active browser session id.
477478
478479 New in SeleniumLibrary 3.2
479480 """
480481 return self .driver .session_id
481482
482483 @keyword
483- def get_source (self ):
484+ def get_source (self ) -> str :
484485 """Returns the entire HTML source of the current page or frame."""
485486 return self .driver .page_source
486487
487488 @keyword
488- def get_title (self ):
489+ def get_title (self ) -> str :
489490 """Returns the title of the current page."""
490491 return self .driver .title
491492
492493 @keyword
493- def get_location (self ):
494+ def get_location (self ) -> str :
494495 """Returns the current browser window URL."""
495496 return self .driver .current_url
496497
497498 @keyword
498- def location_should_be (self , url , message = None ):
499+ def location_should_be (self , url : str , message : Optional [ str ] = None ):
499500 """Verifies that the current URL is exactly ``url``.
500501
501502 The ``url`` argument contains the exact url that should exist in browser.
@@ -513,7 +514,7 @@ def location_should_be(self, url, message=None):
513514 self .info (f"Current location is '{ url } '." )
514515
515516 @keyword
516- def location_should_contain (self , expected , message = None ):
517+ def location_should_contain (self , expected : str , message : Optional [ str ] = None ):
517518 """Verifies that the current URL contains ``expected``.
518519
519520 The ``expected`` argument contains the expected value in url.
@@ -534,14 +535,14 @@ def location_should_contain(self, expected, message=None):
534535 self .info (f"Current location contains '{ expected } '." )
535536
536537 @keyword
537- def log_location (self ):
538+ def log_location (self ) -> str :
538539 """Logs and returns the current browser window URL."""
539540 url = self .get_location ()
540541 self .info (url )
541542 return url
542543
543544 @keyword
544- def log_source (self , loglevel = "INFO" ):
545+ def log_source (self , loglevel : str = "INFO" ) -> str :
545546 """Logs and returns the HTML source of the current page or frame.
546547
547548 The ``loglevel`` argument defines the used log level. Valid log
@@ -553,14 +554,14 @@ def log_source(self, loglevel="INFO"):
553554 return source
554555
555556 @keyword
556- def log_title (self ):
557+ def log_title (self ) -> str :
557558 """Logs and returns the title of the current page."""
558559 title = self .get_title ()
559560 self .info (title )
560561 return title
561562
562563 @keyword
563- def title_should_be (self , title , message = None ):
564+ def title_should_be (self , title : str , message : Optional [ str ] = None ):
564565 """Verifies that the current page title equals ``title``.
565566
566567 The ``message`` argument can be used to override the default error
@@ -592,7 +593,7 @@ def reload_page(self):
592593 self .driver .refresh ()
593594
594595 @keyword
595- def get_selenium_speed (self ):
596+ def get_selenium_speed (self ) -> str :
596597 """Gets the delay that is waited after each Selenium command.
597598
598599 The value is returned as a human-readable string like ``1 second``.
@@ -602,7 +603,7 @@ def get_selenium_speed(self):
602603 return secs_to_timestr (self .ctx .speed )
603604
604605 @keyword
605- def get_selenium_timeout (self ):
606+ def get_selenium_timeout (self ) -> str :
606607 """Gets the timeout that is used by various keywords.
607608
608609 The value is returned as a human-readable string like ``1 second``.
@@ -612,7 +613,7 @@ def get_selenium_timeout(self):
612613 return secs_to_timestr (self .ctx .timeout )
613614
614615 @keyword
615- def get_selenium_implicit_wait (self ):
616+ def get_selenium_implicit_wait (self ) -> str :
616617 """Gets the implicit wait value used by Selenium.
617618
618619 The value is returned as a human-readable string like ``1 second``.
@@ -622,7 +623,7 @@ def get_selenium_implicit_wait(self):
622623 return secs_to_timestr (self .ctx .implicit_wait )
623624
624625 @keyword
625- def set_selenium_speed (self , value ) :
626+ def set_selenium_speed (self , value : str ) -> str :
626627 """Sets the delay that is waited after each Selenium command.
627628
628629 The value can be given as a number that is considered to be
@@ -642,7 +643,7 @@ def set_selenium_speed(self, value):
642643 return old_speed
643644
644645 @keyword
645- def set_selenium_timeout (self , value ) :
646+ def set_selenium_timeout (self , value : str ) -> str :
646647 """Sets the timeout that is used by various keywords.
647648
648649 The value can be given as a number that is considered to be
@@ -664,7 +665,7 @@ def set_selenium_timeout(self, value):
664665 return old_timeout
665666
666667 @keyword
667- def set_selenium_implicit_wait (self , value ) :
668+ def set_selenium_implicit_wait (self , value : str ) -> str :
668669 """Sets the implicit wait value used by Selenium.
669670
670671 The value can be given as a number that is considered to be
@@ -690,7 +691,7 @@ def set_selenium_implicit_wait(self, value):
690691 return old_wait
691692
692693 @keyword
693- def set_browser_implicit_wait (self , value ):
694+ def set_browser_implicit_wait (self , value : str ):
694695 """Sets the implicit wait value used by Selenium.
695696
696697 Same as `Set Selenium Implicit Wait` but only affects the current
0 commit comments