def __init__(self, options=None, capabilities=None, service_url=None, session_id=None): if options == None: self.service = False else: self.service = True self.address = options[0] self.who = options[1] # super(Chrome_Remote, self).__init__(port=port) if service_url is None and session_id is None: raise NameError if capabilities is None: capabilities = DesiredCapabilities.CHROME.copy() self.capabilities = dict(capabilities) self.w3c = True executor = ChromeRemoteConnection(remote_server_addr=service_url) self.session_id = session_id self.command_executor = executor self.command_executor.w3c = self.w3c if type(self.command_executor) is bytes or isinstance( self.command_executor, str): self.command_executor = RemoteConnection(self.command_executor, keep_alive=True) self._is_remote = True self.error_handler = ErrorHandler() self._switch_to = SwitchTo(self) self._mobile = Mobile(self) self.file_detector = LocalFileDetector()
def __init__(self, capabilities=None, service_url=None, session_id=None): if service_url is None and session_id is None: raise NameError if capabilities is None: capabilities = DesiredCapabilities.FIREFOX.copy() self.capabilities = dict(capabilities) self.w3c = True executor = ChromeRemoteConnection(remote_server_addr=service_url) self.session_id = session_id self.command_executor = executor self.command_executor.w3c = self.w3c if type(self.command_executor) is bytes or isinstance(self.command_executor, str): self.command_executor = RemoteConnection(self.command_executor, keep_alive=True) self._is_remote = True self.error_handler = ErrorHandler() self._switch_to = SwitchTo(self) self._mobile = Mobile(self) self.file_detector = LocalFileDetector()
def __init__(self, command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=None, browser_profile=None, proxy=None, keep_alive=False, file_detector=None, session_id=None, w3c=True): """ Create a new driver that will issue commands using the wire protocol. :Args: - command_executor - Either a string representing URL of the remote server or a custom remote_connection.RemoteConnection object. Defaults to 'http://127.0.0.1:4444/wd/hub'. - desired_capabilities - A dictionary of capabilities to request when starting the browser session. Required parameter. - browser_profile - A selenium.webdriver.firefox.firefox_profile.FirefoxProfile object. Only used if Firefox is requested. Optional. - proxy - A selenium.webdriver.common.proxy.Proxy object. The browser session will be started with given proxy settings, if possible. Optional. - keep_alive - Whether to configure remote_connection.RemoteConnection to use HTTP keep-alive. Defaults to False. - file_detector - Pass custom file detector object during instantiation. If None, then default LocalFileDetector() will be used. """ if desired_capabilities is None: raise WebDriverException("Desired Capabilities can't be None") if not isinstance(desired_capabilities, dict): raise WebDriverException( "Desired Capabilities must be a dictionary") if proxy is not None: warnings.warn("Please use FirefoxOptions to set proxy", DeprecationWarning) proxy.add_to_capabilities(desired_capabilities) if (desired_capabilities["browserName"] == 'firefox'): command_executor = FirefoxRemoteConnection( remote_server_addr=command_executor) self.command_executor = command_executor if type(self.command_executor) is bytes or isinstance( self.command_executor, str): self.command_executor = RemoteConnection(command_executor, keep_alive=keep_alive) self._is_remote = True self.session_id = session_id # added self.capabilities = dict(desired_capabilities) self.error_handler = ErrorHandler() self.start_client() if browser_profile is not None: warnings.warn("Please use FirefoxOptions to set browser profile", DeprecationWarning) if session_id: if desired_capabilities["browserName"] != "firefox": self.connect_to_session(desired_capabilities) # added else: pass self.w3c = w3c # modified by zhengchun else: self.start_session(desired_capabilities, browser_profile) self._switch_to = SwitchTo(self) self._mobile = Mobile(self) self.file_detector = file_detector or LocalFileDetector()
def get_context_handles(driver): mobile = Mobile(driver) return mobile.contexts