text
stringlengths
81
112k
Unzip zipfile to a temporary directory. The directory of the unzipped files is returned if success, otherwise None is returned. def unzip_to_temp_dir(zip_file_name): """Unzip zipfile to a temporary directory. The directory of the unzipped files is returned if success, otherwise None is returned. ...
Taps on a given element. :Args: - on_element: The element to tap. def tap(self, on_element): """ Taps on a given element. :Args: - on_element: The element to tap. """ self._actions.append(lambda: self._driver.execute( Command.SINGLE_TAP, {...
Double taps on a given element. :Args: - on_element: The element to tap. def double_tap(self, on_element): """ Double taps on a given element. :Args: - on_element: The element to tap. """ self._actions.append(lambda: self._driver.execute( ...
Touch down at given coordinates. :Args: - xcoord: X Coordinate to touch down. - ycoord: Y Coordinate to touch down. def tap_and_hold(self, xcoord, ycoord): """ Touch down at given coordinates. :Args: - xcoord: X Coordinate to touch down. - ycoord: Y...
Move held tap to specified location. :Args: - xcoord: X Coordinate to move. - ycoord: Y Coordinate to move. def move(self, xcoord, ycoord): """ Move held tap to specified location. :Args: - xcoord: X Coordinate to move. - ycoord: Y Coordinate to mov...
Release previously issued tap 'and hold' command at specified location. :Args: - xcoord: X Coordinate to release. - ycoord: Y Coordinate to release. def release(self, xcoord, ycoord): """ Release previously issued tap 'and hold' command at specified location. :Args: ...
Touch and scroll, moving by xoffset and yoffset. :Args: - xoffset: X offset to scroll to. - yoffset: Y offset to scroll to. def scroll(self, xoffset, yoffset): """ Touch and scroll, moving by xoffset and yoffset. :Args: - xoffset: X offset to scroll to. ...
Touch and scroll starting at on_element, moving by xoffset and yoffset. :Args: - on_element: The element where scroll starts. - xoffset: X offset to scroll to. - yoffset: Y offset to scroll to. def scroll_from_element(self, on_element, xoffset, yoffset): """ Touch an...
Long press on an element. :Args: - on_element: The element to long press. def long_press(self, on_element): """ Long press on an element. :Args: - on_element: The element to long press. """ self._actions.append(lambda: self._driver.execute( ...
Flicks, starting anywhere on the screen. :Args: - xspeed: The X speed in pixels per second. - yspeed: The Y speed in pixels per second. def flick(self, xspeed, yspeed): """ Flicks, starting anywhere on the screen. :Args: - xspeed: The X speed in pixels per s...
Flick starting at on_element, and moving by the xoffset and yoffset with specified speed. :Args: - on_element: Flick will start at center of element. - xoffset: X offset to flick to. - yoffset: Y offset to flick to. - speed: Pixels per second to flick. def flick_ele...
Creates a capabilities with all the options that have been set and returns a dictionary with everything def to_capabilities(self): """ Creates a capabilities with all the options that have been set and returns a dictionary with everything """ caps = self._caps b...
Returns the element with focus, or BODY if nothing has focus. :Usage: :: element = driver.switch_to.active_element def active_element(self): """ Returns the element with focus, or BODY if nothing has focus. :Usage: :: element =...
Switches focus to the specified frame, by index, name, or webelement. :Args: - frame_reference: The name of the window to switch to, an integer representing the index, or a webelement that is an (i)frame to switch to. :Usage: :: driver....
Switches to a new top-level browsing context. The type hint can be one of "tab" or "window". If not specified the browser will automatically select it. :Usage: :: driver.switch_to.new_window('tab') def new_window(self, type_hint=None): """Switches to a new...
Switches focus to the specified window. :Args: - window_name: The name or window handle of the window to switch to. :Usage: :: driver.switch_to.window('main') def window(self, window_name): """ Switches focus to the specified window. :Arg...
Performs all stored actions. def perform(self): """ Performs all stored actions. """ if self._driver.w3c: self.w3c_actions.perform() else: for action in self._actions: action()
Clears actions that are already stored locally and on the remote end def reset_actions(self): """ Clears actions that are already stored locally and on the remote end """ if self._driver.w3c: self.w3c_actions.clear_actions() self._actions = []
Holds down the left mouse button on an element. :Args: - on_element: The element to mouse down. If None, clicks on current mouse position. def click_and_hold(self, on_element=None): """ Holds down the left mouse button on an element. :Args: - on_element: T...
Performs a context-click (right click) on an element. :Args: - on_element: The element to context-click. If None, clicks on current mouse position. def context_click(self, on_element=None): """ Performs a context-click (right click) on an element. :Args: -...
Double-clicks an element. :Args: - on_element: The element to double-click. If None, clicks on current mouse position. def double_click(self, on_element=None): """ Double-clicks an element. :Args: - on_element: The element to double-click. If No...
Holds down the left mouse button on the source element, then moves to the target element and releases the mouse button. :Args: - source: The element to mouse down. - target: The element to mouse up. def drag_and_drop(self, source, target): """ Holds down the left m...
Holds down the left mouse button on the source element, then moves to the target offset and releases the mouse button. :Args: - source: The element to mouse down. - xoffset: X offset to move to. - yoffset: Y offset to move to. def drag_and_drop_by_offset(self, source, xof...
Sends a key press only, without releasing it. Should only be used with modifier keys (Control, Alt and Shift). :Args: - value: The modifier key to send. Values are defined in `Keys` class. - element: The element to send keys. If None, sends a key to current focused eleme...
Moving the mouse to an offset from current mouse position. :Args: - xoffset: X offset to move to, as a positive or negative integer. - yoffset: Y offset to move to, as a positive or negative integer. def move_by_offset(self, xoffset, yoffset): """ Moving the mouse to an offse...
Moving the mouse to the middle of an element. :Args: - to_element: The WebElement to move to. def move_to_element(self, to_element): """ Moving the mouse to the middle of an element. :Args: - to_element: The WebElement to move to. """ if self._driver....
Move the mouse by an offset of the specified element. Offsets are relative to the top-left corner of the element. :Args: - to_element: The WebElement to move to. - xoffset: X offset to move to. - yoffset: Y offset to move to. def move_to_element_with_offset(self, to_eleme...
Pause all inputs for the specified duration in seconds def pause(self, seconds): """ Pause all inputs for the specified duration in seconds """ if self._driver.w3c: self.w3c_actions.pointer_action.pause(seconds) self.w3c_actions.key_action.pause(seconds) else: ...
Releasing a held mouse button on an element. :Args: - on_element: The element to mouse up. If None, releases on current mouse position. def release(self, on_element=None): """ Releasing a held mouse button on an element. :Args: - on_element: The element to...
Sends keys to current focused element. :Args: - keys_to_send: The keys to send. Modifier keys constants can be found in the 'Keys' class. def send_keys(self, *keys_to_send): """ Sends keys to current focused element. :Args: - keys_to_send: The keys to sen...
Sends keys to an element. :Args: - element: The element to send keys. - keys_to_send: The keys to send. Modifier keys constants can be found in the 'Keys' class. def send_keys_to_element(self, element, *keys_to_send): """ Sends keys to an element. :Args: ...
Sets the options Browser Attach Timeout :Args: - value: Timeout in milliseconds def browser_attach_timeout(self, value): """ Sets the options Browser Attach Timeout :Args: - value: Timeout in milliseconds """ if not isinstance(value, int): ...
Sets the options Element Scroll Behavior :Args: - value: 0 - Top, 1 - Bottom def element_scroll_behavior(self, value): """ Sets the options Element Scroll Behavior :Args: - value: 0 - Top, 1 - Bottom """ if value not in [ElementScrollBehavior.TOP, El...
Sets the options File Upload Dialog Timeout value :Args: - value: Timeout in milliseconds def file_upload_dialog_timeout(self, value): """ Sets the options File Upload Dialog Timeout value :Args: - value: Timeout in milliseconds """ if not isinstance...
Marshals the IE options to the correct object. def to_capabilities(self): """Marshals the IE options to the correct object.""" caps = self._caps opts = self._options.copy() if len(self._arguments) > 0: opts[self.SWITCHES] = ' '.join(self._arguments) if len(self._ad...
:Returns: A list of encoded extensions that will be loaded into chrome def extensions(self): """ :Returns: A list of encoded extensions that will be loaded into chrome """ encoded_extensions = [] for ext in self._extension_files: file_ = open(ext, 'rb') #...
Adds the path to the extension to a list that will be used to extract it to the ChromeDriver :Args: - extension: path to the \\*.crx file def add_extension(self, extension): """ Adds the path to the extension to a list that will be used to extract it to the ChromeDrive...
Sets the headless argument :Args: value: boolean value indicating to set the headless option def headless(self, value): """ Sets the headless argument :Args: value: boolean value indicating to set the headless option """ args = {'--headless'} ...
Creates a capabilities with all the options that have been set :Returns: A dictionary with everything def to_capabilities(self): """ Creates a capabilities with all the options that have been set :Returns: A dictionary with everything """ caps = self._caps chro...
Looks up an element. Logs and re-raises ``WebDriverException`` if thrown. def _find_element(driver, by): """Looks up an element. Logs and re-raises ``WebDriverException`` if thrown.""" try: return driver.find_element(*by) except NoSuchElementException as e: raise e except WebDri...
Gets the text of the Alert. def text(self): """ Gets the text of the Alert. """ if self.driver.w3c: return self.driver.execute(Command.W3C_GET_ALERT_TEXT)["value"] else: return self.driver.execute(Command.GET_ALERT_TEXT)["value"]
Dismisses the alert available. def dismiss(self): """ Dismisses the alert available. """ if self.driver.w3c: self.driver.execute(Command.W3C_DISMISS_ALERT) else: self.driver.execute(Command.DISMISS_ALERT)
Accepts the alert available. Usage:: Alert(driver).accept() # Confirm a alert dialog. def accept(self): """ Accepts the alert available. Usage:: Alert(driver).accept() # Confirm a alert dialog. """ if self.driver.w3c: self.driver.execute(Com...
Send Keys to the Alert. :Args: - keysToSend: The text to be sent to Alert. def send_keys(self, keysToSend): """ Send Keys to the Alert. :Args: - keysToSend: The text to be sent to Alert. """ if self.driver.w3c: self.driver.execute(Comman...
Sets the port that WebDriver will be running on def port(self, port): """ Sets the port that WebDriver will be running on """ if not isinstance(port, int): raise WebDriverException("Port needs to be an integer") try: port = int(port) if port <...
A zipped, base64 encoded string of profile directory for use with remote WebDriver JSON wire protocol def encoded(self): """ A zipped, base64 encoded string of profile directory for use with remote WebDriver JSON wire protocol """ self.update_preferences() fp = B...
writes the current user prefs dictionary to disk def _write_user_prefs(self, user_prefs): """ writes the current user prefs dictionary to disk """ with open(self.userPrefs, "w") as f: for key, value in user_prefs.items(): f.write('user_pref("%s", %s);\n' % (k...
Installs addon from a filepath, url or directory of addons in the profile. - path: url, absolute path to .xpi, or directory of addons - unpack: whether to unpack unless specified otherwise in the install.rdf def _install_extension(self, addon, unpack=True): """ I...
Returns a dictionary of details about the addon. :param addon_path: path to the add-on directory or XPI Returns:: {'id': u'rainbow@colors.org', # id of the addon 'version': u'1.4', # version of the addon 'name': u'Rainbow', # nam...
Submits a form. def submit(self): """Submits a form.""" if self._w3c: form = self.find_element(By.XPATH, "./ancestor-or-self::form") self._parent.execute_script( "var e = arguments[0].ownerDocument.createEvent('Event');" "e.initEvent('submit', tru...
Gets the given property of the element. :Args: - name - Name of the property to retrieve. :Usage: :: text_length = target_element.get_property("text_length") def get_property(self, name): """ Gets the given property of the element. :Ar...
Gets the given attribute or property of the element. This method will first try to return the value of a property with the given name. If a property with that name doesn't exist, it returns the value of the attribute with the same name. If there's no attribute with that name, ``None`` i...
Simulates typing into the element. :Args: - value - A string for typing, or setting form fields. For setting file inputs, this could be a local file path. Use this to send simple key events or to fill out form fields:: form_textfield = driver.find_element_by_nam...
Whether the element is visible to a user. def is_displayed(self): """Whether the element is visible to a user.""" # Only go into this conditional for browsers that don't use the atom themselves if self._w3c: return self.parent.execute_script( "return (%s).apply(null,...
THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where on the screen an element is so that we can click it. This method should cause the element to be scrolled into view. Returns the top lefthand corner location on the screen, or ``None`` if the element is not visible. de...
The size of the element. def size(self): """The size of the element.""" size = {} if self._w3c: size = self._execute(Command.GET_ELEMENT_RECT)['value'] else: size = self._execute(Command.GET_ELEMENT_SIZE)['value'] new_size = {"height": size["height"], ...
The location of the element in the renderable canvas. def location(self): """The location of the element in the renderable canvas.""" if self._w3c: old_loc = self._execute(Command.GET_ELEMENT_RECT)['value'] else: old_loc = self._execute(Command.GET_ELEMENT_LOCATION)['val...
A dictionary with the size and location of the element. def rect(self): """A dictionary with the size and location of the element.""" if self._w3c: return self._execute(Command.GET_ELEMENT_RECT)['value'] else: rect = self.size.copy() rect.update(self.location...
Saves a screenshot of the current element to a PNG image file. Returns False if there is any IOError, else returns True. Use full paths in your filename. :Args: - filename: The full path you wish to save your screenshot to. This should end with a `.png` extension. ...
Executes a command against the underlying HTML element. Args: command: The name of the command to _execute as a string. params: A dictionary of named parameters to send with the command. Returns: The command's JSON response loaded into a dictionary object. def _execute(s...
Find an element given a By strategy and locator. Prefer the find_element_by_* methods when possible. :Usage: :: element = element.find_element(By.ID, 'foo') :rtype: WebElement def find_element(self, by=By.ID, value=None): """ Find an element given ...
Find elements given a By strategy and locator. Prefer the find_elements_by_* methods when possible. :Usage: :: element = element.find_elements(By.CLASS_NAME, 'foo') :rtype: list of WebElement def find_elements(self, by=By.ID, value=None): """ Find ...
Closes the browser and shuts down the WebKitGTKDriver executable that is started when starting the WebKitGTKDriver def quit(self): """ Closes the browser and shuts down the WebKitGTKDriver executable that is started when starting the WebKitGTKDriver """ try: ...
Starts the Service. :Exceptions: - WebDriverException : Raised either when it can't start the service or when it can't connect to the service def start(self): """ Starts the Service. :Exceptions: - WebDriverException : Raised either when it can't start the...
Stops the service. def stop(self): """ Stops the service. """ if self.log_file != PIPE and not (self.log_file == DEVNULL and _HAS_NATIVE_DEVNULL): try: self.log_file.close() except Exception: pass if self.process is None: ...
Launches the browser for the given profile name. It is assumed the profile already exists. def launch_browser(self, profile, timeout=30): """Launches the browser for the given profile name. It is assumed the profile already exists. """ self.profile = profile self._start...
Kill the browser. This is useful when the browser is stuck. def kill(self): """Kill the browser. This is useful when the browser is stuck. """ if self.process: self.process.kill() self.process.wait()
Blocks until the extension is connectable in the firefox. def _wait_until_connectable(self, timeout=30): """Blocks until the extension is connectable in the firefox.""" count = 0 while not utils.is_connectable(self.profile.port): if self.process.poll() is not None: #...
Return the command to start firefox. def _get_firefox_start_cmd(self): """Return the command to start firefox.""" start_cmd = "" if platform.system() == "Darwin": start_cmd = "/Applications/Firefox.app/Contents/MacOS/firefox-bin" # fallback to homebrew installation for m...
Returns the fully qualified path by searching Path of the given name def which(self, fname): """Returns the fully qualified path by searching Path of the given name""" for pe in os.environ['PATH'].split(os.pathsep): checkname = os.path.join(pe, fname) if os.acces...
Get headers for remote request. :Args: - parsed_url - The parsed url - keep_alive (Boolean) - Is this a keep-alive connection (default: False) def get_remote_connection_headers(cls, parsed_url, keep_alive=False): """ Get headers for remote request. :Args: - ...
Send a command to the remote server. Any path subtitutions required for the URL mapped to the command should be included in the command parameters. :Args: - command - A string specifying the command to execute. - params - A dictionary of named parameters to send with the comm...
Send an HTTP request to the remote server. :Args: - method - A string for the HTTP method to send the request with. - url - A string for the URL to send the request to. - body - A string for request body. Ignored unless method is POST or PUT. :Returns: A dictionary...
Returns a list of all selected options belonging to this select tag def all_selected_options(self): """Returns a list of all selected options belonging to this select tag""" ret = [] for opt in self.options: if opt.is_selected(): ret.append(opt) return ret
Select all options that have a value matching the argument. That is, when given "foo" this would select an option like: <option value="foo">Bar</option> :Args: - value - The value to match against throws NoSuchElementException If there is no option with specifi...
Select the option at the given index. This is done by examing the "index" attribute of an element, and not merely by counting. :Args: - index - The option at this index will be selected throws NoSuchElementException If there is no option with specified index in SELECT def...
Select all options that display text matching the argument. That is, when given "Bar" this would select an option like: <option value="foo">Bar</option> :Args: - text - The visible text to match against throws NoSuchElementException If there is no option with...
Clear all selected entries. This is only valid when the SELECT supports multiple selections. throws NotImplementedError If the SELECT does not support multiple selections def deselect_all(self): """Clear all selected entries. This is only valid when the SELECT supports multiple selections. ...
Deselect all options that have a value matching the argument. That is, when given "foo" this would deselect an option like: <option value="foo">Bar</option> :Args: - value - The value to match against throws NoSuchElementException If there is no option with s...
Deselect the option at the given index. This is done by examing the "index" attribute of an element, and not merely by counting. :Args: - index - The option at this index will be deselected throws NoSuchElementException If there is no option with specified index in SELECT...
Deselect all options that display text matching the argument. That is, when given "Bar" this would deselect an option like: <option value="foo">Bar</option> :Args: - text - The visible text to match against def deselect_by_visible_text(self, text): """Deselect all...
Creates a capabilities with all the options that have been set and returns a dictionary with everything def to_capabilities(self): """ Creates a capabilities with all the options that have been set and returns a dictionary with everything """ capabilities = ChromeOptions...
Uploads a file to Google Cloud Storage. Args: auth_http: An authorized httplib2.Http instance. project_id: The project to upload to. bucket_name: The bucket to upload to. file_path: Path to the file to upload. object_name: The name within the bucket to upload to. acl...
Runs the OAuth 2.0 installed application flow. Returns: An authorized httplib2.Http instance. def _authenticate(secrets_file): """Runs the OAuth 2.0 installed application flow. Returns: An authorized httplib2.Http instance. """ flow = oauthclient.flow_from_clientsecrets( secre...
Sets autodetect setting. :Args: - value: The autodetect value. def auto_detect(self, value): """ Sets autodetect setting. :Args: - value: The autodetect value. """ if isinstance(value, bool): if self.autodetect is not value: ...
Sets ftp proxy setting. :Args: - value: The ftp proxy value. def ftp_proxy(self, value): """ Sets ftp proxy setting. :Args: - value: The ftp proxy value. """ self._verify_proxy_type_compatibility(ProxyType.MANUAL) self.proxyType = ProxyType.MA...
Sets http proxy setting. :Args: - value: The http proxy value. def http_proxy(self, value): """ Sets http proxy setting. :Args: - value: The http proxy value. """ self._verify_proxy_type_compatibility(ProxyType.MANUAL) self.proxyType = ProxyTy...
Sets noproxy setting. :Args: - value: The noproxy value. def no_proxy(self, value): """ Sets noproxy setting. :Args: - value: The noproxy value. """ self._verify_proxy_type_compatibility(ProxyType.MANUAL) self.proxyType = ProxyType.MANUAL ...
Sets proxy autoconfig url setting. :Args: - value: The proxy autoconfig url value. def proxy_autoconfig_url(self, value): """ Sets proxy autoconfig url setting. :Args: - value: The proxy autoconfig url value. """ self._verify_proxy_type_compatibility(...
Sets https proxy setting. :Args: - value: The https proxy value. def ssl_proxy(self, value): """ Sets https proxy setting. :Args: - value: The https proxy value. """ self._verify_proxy_type_compatibility(ProxyType.MANUAL) self.proxyType = Prox...
Sets socks proxy setting. :Args: - value: The socks proxy value. def socks_proxy(self, value): """ Sets socks proxy setting. :Args: - value: The socks proxy value. """ self._verify_proxy_type_compatibility(ProxyType.MANUAL) self.proxyType = Pr...
Sets socks proxy username setting. :Args: - value: The socks proxy username value. def socks_username(self, value): """ Sets socks proxy username setting. :Args: - value: The socks proxy username value. """ self._verify_proxy_type_compatibility(ProxyT...
Sets socks proxy password setting. :Args: - value: The socks proxy password value. def socks_password(self, value): """ Sets socks proxy password setting. :Args: - value: The socks proxy password value. """ self._verify_proxy_type_compatibility(ProxyT...
Adds proxy information as capability in specified capabilities. :Args: - capabilities: The capabilities to which proxy will be added. def add_to_capabilities(self, capabilities): """ Adds proxy information as capability in specified capabilities. :Args: - capabilitie...
Resolve a hostname to an IP, preferring IPv4 addresses. We prefer IPv4 so that we don't change behavior from previous IPv4-only implementations, and because some drivers (e.g., FirefoxDriver) do not support IPv6 connections. If the optional port number is provided, only IPs that listen on the given ...
Joins a hostname and port together. This is a minimal implementation intended to cope with IPv6 literals. For example, _join_host_port('::1', 80) == '[::1]:80'. :Args: - host - A hostname. - port - An integer port. def join_host_port(host, port): """Joins a hostname and port together....
Tries to connect to the server at port to see if it is running. :Args: - port - The port to connect. def is_connectable(port, host="localhost"): """ Tries to connect to the server at port to see if it is running. :Args: - port - The port to connect. """ socket_ = None try: ...
Tries to connect to the HTTP server at /status path and specified port to see if it responds successfully. :Args: - port - The port to connect. def is_url_connectable(port): """ Tries to connect to the HTTP server at /status path and specified port to see if it responds successfully. :Ar...
Processes the values that will be typed in the element. def keys_to_typing(value): """Processes the values that will be typed in the element.""" typing = [] for val in value: if isinstance(val, Keys): typing.append(val) elif isinstance(val, int): val = str(val) ...
Doc method extension for saving the current state as a displaCy visualization. def to_html(doc, output="/tmp", style="dep"): """Doc method extension for saving the current state as a displaCy visualization. """ # generate filename from first six non-punct tokens file_name = "-".join([w.text for...