def set_browser_implicit_wait(self, value): """Sets the implicit wait value used by Selenium. Same as `Set Selenium Implicit Wait` but only affects the current browser. """ self.driver.implicitly_wait(timestr_to_secs(value))
def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page Screenshot', screenshot_root_directory=None): """SeleniumLibrary can be imported with several optional arguments. - ``timeout``: Default value for `timeouts` used with ``Wait ...`` keywords. - ``implicit_wait``: Default value for `implicit wait` used when locating elements. - ``run_on_failure``: Default action for the `run-on-failure functionality`. - ``screenshot_root_directory``: Location where possible screenshots are created. If not given, the directory where the log file is written is used. """ self.timeout = timestr_to_secs(timeout) self.implicit_wait = timestr_to_secs(implicit_wait) self.speed = 0.0 self.run_on_failure_keyword \ = RunOnFailureKeywords.resolve_keyword(run_on_failure) self._running_on_failure_keyword = False self.screenshot_root_directory = screenshot_root_directory libraries = [ AlertKeywords(self), BrowserManagementKeywords(self), CookieKeywords(self), ElementKeywords(self), FormElementKeywords(self), FrameKeywords(self), JavaScriptKeywords(self), RunOnFailureKeywords(self), ScreenshotKeywords(self), SelectElementKeywords(self), TableElementKeywords(self), WaitingKeywords(self), WindowKeywords(self) ] self._drivers = WebDriverCache() DynamicCore.__init__(self, libraries) self.ROBOT_LIBRARY_LISTENER = LibraryListener() self._element_finder = ElementFinder(self)
def set_selenium_speed(self, value): """Sets the delay that is waited after each Selenium command. The value can be given as a number that is considered to be seconds or as a human readable string like ``1 second``. The previous value is returned and can be used to restore the original value later if needed. See the `Selenium Speed` section above for more information. Example: | `Set Selenium Speed` | 0.5 seconds | """ old_speed = self.get_selenium_speed() self.ctx.speed = timestr_to_secs(value) for driver in self.drivers.active_drivers: self._monkey_patch_speed(driver) return old_speed
def set_selenium_timeout(self, value): """Sets the timeout that is used by various keywords. The value can be given as a number that is considered to be seconds or as a human readable string like ``1 second``. The previous value is returned and can be used to restore the original value later if needed. See the `Timeout` section above for more information. Example: | ${orig timeout} = | `Set Selenium Timeout` | 15 seconds | | `Open page that loads slowly` | | `Set Selenium Timeout` | ${orig timeout} | """ old_timeout = self.get_selenium_timeout() self.ctx.timeout = timestr_to_secs(value) for driver in self.drivers.active_drivers: driver.set_script_timeout(self.ctx.timeout) return old_timeout
def set_selenium_implicit_wait(self, value): """Sets the implicit wait value used by Selenium. The value can be given as a number that is considered to be seconds or as a human readable string like ``1 second``. The previous value is returned and can be used to restore the original value later if needed. This keyword sets the implicit wait for all opened browsers. Use `Set Browser Implicit Wait` to set it only to the current browser. See the `Implicit wait` section above for more information. Example: | ${orig wait} = | `Set Selenium Implicit Wait` | 10 seconds | | `Perform AJAX call that is slow` | | `Set Selenium Implicit Wait` | ${orig wait} | """ old_wait = self.get_selenium_implicit_wait() self.ctx.implicit_wait = timestr_to_secs(value) for driver in self.drivers.active_drivers: driver.implicitly_wait(self.ctx.implicit_wait) return old_wait
def select_window(self, locator='MAIN', timeout=None): """Selects browser window matching ``locator``. If the window is found, all subsequent commands use the selected window, until this keyword is used again. If the window is not found, this keyword fails. The previous window handle is returned, and can be used to return back to it later. Notice that in this context _window_ means a pop-up window opened when doing something on an existing window. It is not possible to select windows opened with `Open Browser`, `Switch Browser` must be used instead. Notice also that alerts should be handled with `Handle Alert` or other alert related keywords. The ``locator`` can be specified using different strategies somewhat similarly as when `locating elements` on pages. - By default the ``locator`` is matched against window handle, name, title, and URL. Matching is done in that order and the the first matching window is selected. - The ``locator`` can specify an explicit strategy by using format ``strategy:value`` (recommended) or ``strategy=value``. Supported strategies are ``name``, ``title`` and ``url``, which match windows using name, title, and URL, respectively. Additionally, ``default`` can be used to explicitly use the default strategy explained above. - If the ``locator`` is ``NEW`` (case-insensitive), the latest opened window is selected. It is an error if this is the same as the current window. - If the ``locator`` is ``MAIN`` (default, case-insensitive), the main window is selected. - If the ``locator`` is ``CURRENT`` (case-insensitive), nothing is done. This effectively just returns the current window handle. - If the ``locator`` is not a string, it is expected to be a list of window handles _to exclude_. Such a list of excluded windows can be get from `Get Window Handles` prior to doing an action that opens a new window. The ``timeout`` is used to specify how long keyword will poll to select the new window. The ``timeout`` is new in SeleniumLibrary 3.2. Example: | `Click Link` | popup1 | | # Open new window | | `Select Window` | example | | # Select window using default strategy | | `Title Should Be` | Pop-up 1 | | | `Click Button` | popup2 | | # Open another window | | ${handle} = | `Select Window` | NEW | # Select latest opened window | | `Title Should Be` | Pop-up 2 | | | `Select Window` | ${handle} | | # Select window using handle | | `Title Should Be` | Pop-up 1 | | | `Select Window` | MAIN | | # Select the main window | | `Title Should Be` | Main | | | ${excludes} = | `Get Window Handles` | | # Get list of current windows | | `Click Link` | popup3 | | # Open one more window | | `Select Window` | ${excludes} | | # Select window using excludes | | `Title Should Be` | Pop-up 3 | | *NOTE:* - The ``strategy:value`` syntax is only supported by SeleniumLibrary 3.0 and newer. - Prior to SeleniumLibrary 3.0 matching windows by name, title and URL was case-insensitive. - Earlier versions supported aliases ``None``, ``null`` and the empty string for selecting the main window, and alias ``self`` for selecting the current window. Support for these aliases were removed in SeleniumLibrary 3.2. """ epoch = time.time() timeout = epoch if is_falsy(timeout) else timestr_to_secs(timeout) + epoch try: return self.driver.current_window_handle except NoSuchWindowException: pass finally: self._window_manager.select(locator, timeout)
def get_timeout(self, timeout=None): if is_noney(timeout): return self.ctx.timeout return timestr_to_secs(timeout)