• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.is_connectable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中selenium.webdriver.common.utils.is_connectable函数的典型用法代码示例。如果您正苦于以下问题:Python is_connectable函数的具体用法?Python is_connectable怎么用?Python is_connectable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了is_connectable函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_driver

    def get_driver(self):
        """
        Only creates the driver if not present and returns it.

        :return: ``WebDriver`` instance.
        """

        # Dedicated mode
        if hasattr(settings, 'CRAWLABLE_PHANTOMJS_DEDICATED_MODE') and settings.CRAWLABLE_PHANTOMJS_DEDICATED_MODE:
            if not self._web_driver:
                self._web_driver = DedicatedWebDriver(
                    port=getattr(settings, 'CRAWLABLE_PHANTOMJS_DEDICATED_PORT', 8910)
                )
            elif not is_connectable(self._web_driver.service.port):
                raise RuntimeError('Cannot connect to dedicated PhantomJS instance on: %s' %
                                    self._web_driver.service.service_url)
        # Instance based mode (more for testing purposes). When debugging, you can even replace the PhantomJS webdriver
        # with firefox and remove the arguments to the web driver constructor below.
        else:
            if not self._web_driver:
                self._web_driver = WebDriver(service_args=self.service_args)
            elif not is_connectable(self._web_driver.service.port):
                self._web_driver.service.stop()
                self._web_driver = WebDriver(service_args=self.service_args)

        # Make sure it doesn't time out.
        self._web_driver.set_script_timeout(30)

        return self._web_driver
开发者ID:jfterpstra,项目名称:onepercentclub-site,代码行数:29,代码来源:middleware.py


示例2: start

    def start(self):
        """
        Starts the ChromeDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        env = self.env or os.environ
        try:
            self.process = subprocess.Popen([
              self.path,
              "--port=%d" % self.port] +
              self.service_args, env=env, stdout=PIPE, stderr=PIPE)
        except:
            raise WebDriverException(
                "'" + os.path.basename(self.path) + "' executable needs to be \
                available in the path. Please look at \
                http://docs.seleniumhq.org/download/#thirdPartyDrivers \
                and read up at \
                https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver")
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the '" +
                                         os.path.basename(self.path) + "'")
开发者ID:bilalnazer,项目名称:selenium,代码行数:28,代码来源:service.py


示例3: start

    def start(self):
        """
        Starts the GeckoDriver "wires" Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        env = self.env or os.environ
        self.log_file = file("geckodriver.log", "w")
        try:
            #import pdb; pdb.set_trace()
            self.process = subprocess.Popen([
              self.path,
              "-b", self.firefox_binary, '--webdriver-port', "%d" % self.port],
              env=env, stdout=self.log_file, stderr=self.log_file)
        except Exception as e:
            raise WebDriverException(
                "'" + os.path.basename(self.path) + "' executable needs to be \
                available in the path.\n %s" % str(e))
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the '" +
                                         os.path.basename(self.path) + "'")
开发者ID:DhamodharanGH,项目名称:local,代码行数:27,代码来源:service.py


示例4: _wait_until_connectable

    def _wait_until_connectable(self):
        """Blocks until the extension is connectable in the firefox.

        The base class implements this by checking utils.is_connectable() every
        second (sleep_for == 1) and failing after 30 attempts (max_tries ==
        30). Expriments showed that once a firefox can't be connected to, it's
        better to start a new one instead so we don't wait 30 seconds to fail
        in the end (the caller should catch WebDriverException and starts a new
        firefox).
        """
        connectable = False
        max_tries = 6
        sleep_for = 1
        for count in range(1, max_tries):
            connectable = utils.is_connectable(self.profile.port)
            if connectable:
                break
            logger.debug('Cannot connect to process %d with port: %d, count %d'
                         % (self.process.pid, self.profile.port, count))
            if self.process.poll() is not None:
                # Browser has exited
                raise selenium_exceptions.WebDriverException("The browser appears to have exited "
                      "before we could connect. If you specified a log_file in "
                      "the FirefoxBinary constructor, check it for details.")
            time.sleep(sleep_for)
        if not connectable:
            self.kill()
            raise selenium_exceptions.WebDriverException(
                      "Can't load the profile. Profile "
                      "dir: %s. If you specified a log_file in the "
                      "FirefoxBinary constructor, check it for details." %
                      self.profile.profile_dir)
        return connectable
开发者ID:ikornaselur,项目名称:sst,代码行数:33,代码来源:browsers.py


示例5: stop

    def stop(self):
        """
        Tells the EdgeDriver to stop and cleans up the process
        """
        #If its dead dont worry
        if self.process is None:
            return

        #Tell the Server to die!
        try:
            from urllib import request as url_request
        except ImportError:
            import urllib2 as url_request

        url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port)
        count = 0
        while utils.is_connectable(self.port):
            if count == 30:
               break
            count += 1
            time.sleep(1)

        #Tell the Server to properly die in case
        try:
            if self.process:
                self.process.stdout.close()
                self.process.stderr.close()
                self.process.kill()
                self.process.wait()
        except WindowsError:
            # kill may not be available under windows environment
            pass
开发者ID:nvonop,项目名称:selenium,代码行数:32,代码来源:service.py


示例6: start

    def start(self):
        """
        Starts PhantomJS with GhostDriver.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        try:
            '''
            self.process = subprocess.Popen(self.service_args, stdin=subprocess.PIPE,
                                            close_fds=True, stdout=self._log,
                                            stderr=self._log)
            '''
            self.process = subprocess.Popen(self.service_args,
                                            stdout=self._log, stderr=self._log)                             

        except Exception as e:
            raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                 raise WebDriverException("Can not connect to GhostDriver")
开发者ID:ktan2020,项目名称:legacy-automation,代码行数:25,代码来源:service.py


示例7: __init__

    def __init__(self, port=DEFAULT_PORT, timeout=DEFAULT_TIMEOUT):
        self.port = port
        if self.port == 0:
            self.port = utils.free_port()

        # Create IE Driver instance of the unmanaged code
        try:
            self.iedriver = CDLL(os.path.join(os.path.dirname(__file__),"win32", "IEDriver.dll"))
        except WindowsError:
            try:
                self.iedriver = CDLL(os.path.join(os.path.dirname(__file__),"x64", "IEDriver.dll"))
            except WindowsError:
                raise WebDriverException("Unable to load the IEDriver.dll component")
        self.ptr = self.iedriver.StartServer(self.port)

        seconds = 0
        while not utils.is_connectable(self.port):
            seconds += 1
            if seconds > DEFAULT_TIMEOUT:
                raise RuntimeError("Unable to connect to IE")
            time.sleep(1)

        RemoteWebDriver.__init__(
            self,
            command_executor='http://localhost:%d' % self.port,
            desired_capabilities=DesiredCapabilities.INTERNETEXPLORER)
开发者ID:hhakkala,项目名称:robotframework-selenium2library-boilerplate,代码行数:26,代码来源:webdriver.py


示例8: stop

    def stop(self):
        """ 
        Tells the ChromeDriver to stop and cleans up the process
        """
        #If its dead dont worry
        if self.process is None:
            return

        #Tell the Server to die!
        import urllib2
        try:
            urllib2.urlopen("http://127.0.0.01:%d/shutdown" % self.port)

            # make sure that shutdown worked by testing the port has gone away
            count = 0
            while utils.is_connectable(self.port):
                if count == 30:
                   break 
                count += 1
                time.sleep(1)
        finally:
        #Tell the Server to properly die in case
            if self.process:
                try:
                    os.kill(self.process.pid, signal.SIGTERM)
                    os.wait()
                except AttributeError:
                    # kill may not be available under windows environment
                    pass
开发者ID:DreamYa0,项目名称:PythonProject,代码行数:29,代码来源:service.py


示例9: start

    def start(self):
        """
        Starts the SafariDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        kwargs = dict()
        if self.quiet:
            devnull_out = open(devnull, 'w')
            kwargs.update(stdout=devnull_out,
                          stderr=devnull_out)
        try:
            self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port],
                                            **kwargs)
        except:
            raise WebDriverException(
                "SafariDriver executable needs to be available in the path.")
        time.sleep(10)
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the SafariDriver")
开发者ID:Athsheep,项目名称:Flask_Web_Development,代码行数:26,代码来源:service.py


示例10: start

 def start(self):
     """ Starts the ChromeDriver Service. 
         @Exceptions
             WebDriverException : Raised either when it can't start the service
                 or when it can't connect to the service"""
     try:
         self.process = subprocess.Popen([self.path, "--port=%d" % self.port], stdout=PIPE, stderr=PIPE)
     except:
         raise WebDriverException(self.MISSING_TEXT)
     count = 0
     while not utils.is_connectable(self.port):
         count += 1
         time.sleep(1)
         if count == 30:
             raise WebDriverException("Can not connect to the ChromeDriver")
开发者ID:hali4ka,项目名称:robotframework-selenium2library,代码行数:15,代码来源:service.py


示例11: _wait_until_connectable

 def _wait_until_connectable(self):
     """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:
             # Browser has exited
             raise WebDriverException("The browser appears to have exited "
                   "before we could connect. If you specified a log_file in "
                   "the FirefoxBinary constructor, check it for details.")
         if count == 30:
             self.kill()
             raise WebDriverException("Can't load the profile. Profile "
                   "Dir: %s If you specified a log_file in the "
                   "FirefoxBinary constructor, check it for details.")
         count += 1
         time.sleep(1)
     return True
开发者ID:217,项目名称:selenium,代码行数:17,代码来源:firefox_binary.py


示例12: start

    def start(self):
        """
        Starts PhantomJS with GhostDriver.

        :exception WebDriverException: Raised either when it can't start the service
                                        or when it can't connect to the service.
        """
        try:
            self.process = subprocess.Popen(self.pre_command + self.service_args, stdin=subprocess.PIPE,
                                            close_fds=platform.system() != 'Windows',
                                            stdout=self._log, stderr=self._log)
        except Exception as e:
            raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to GhostDriver on port {}".format(self.port))
开发者ID:PumucklOnTheAir,项目名称:TestFramework,代码行数:19,代码来源:service_phantomjs_extended.py


示例13: start

 def start(self):
     """
     Starts the OperaDriver Service. 
     
     :Exceptions:
      - WebDriverException : Raised either when it can't start the service
        or when it can't connect to the service
     """
     try:
         self.process = subprocess.Popen(["java", "-jar", self.path, "-port", "%s" % self.port])
     except:
         raise WebDriverException(
             "OperaDriver executable needs to be available in the path.")
     time.sleep(10)
     count = 0
     while not utils.is_connectable(self.port):
         count += 1
         time.sleep(1)
         if count == 30:
              raise WebDriverException("Can not connect to the OperaDriver")
开发者ID:AlfZombie,项目名称:selenium,代码行数:20,代码来源:service.py


示例14: start

    def start(self):
        """
        Starts the ChromeDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it cannot find the
           executable, when it does not have permissions for the
           executable, or when it cannot connect to the service.
         - Possibly other Exceptions in rare circumstances (OSError, etc).
        """
        env = self.env or os.environ
        try:
            self.process = subprocess.Popen([
              self.path,
              "--port=%d" % self.port] +
              self.service_args, env=env, stdout=PIPE, stderr=PIPE)
        except OSError as err:
            docs_msg = "Please see " \
                   "https://sites.google.com/a/chromium.org/chromedriver/home"
            if err.errno == errno.ENOENT:
                raise WebDriverException(
                    "'%s' executable needs to be in PATH. %s" % (
                        os.path.basename(self.path), docs_msg)
                )
            elif err.errno == errno.EACCES:
                raise WebDriverException(
                    "'%s' executable may have wrong permissions. %s" % (
                        os.path.basename(self.path), docs_msg)
                )
            else:
                raise
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                raise WebDriverException("Can not connect to the '" +
                                         os.path.basename(self.path) + "'")
开发者ID:217,项目名称:selenium,代码行数:38,代码来源:service.py


示例15: start

    def start(self):
        """
        Starts the EdgeDriver Service.

        :Exceptions:
         - WebDriverException : Raised either when it can't start the service
           or when it can't connect to the service
        """
        try:
            cmd = [self.path, "--port=%d" % self.port]
            self.process = subprocess.Popen(cmd,
                    stdout=PIPE, stderr=PIPE)
        except TypeError:
            raise
        except:
            raise WebDriverException(
                "The EdgeDriver executable needs to be available in the path. "
                "Please download from http://go.microsoft.com/fwlink/?LinkId=619687 ")
        count = 0
        while not utils.is_connectable(self.port):
            count += 1
            time.sleep(1)
            if count == 30:
                 raise WebDriverException("Can not connect to the EdgeDriver")
开发者ID:DhamodharanGH,项目名称:local,代码行数:24,代码来源:service.py


示例16: is_busy

def is_busy(port_no):
    """Return True if port is already in use."""
    return is_connectable(port_no)
开发者ID:mjuarezm,项目名称:tor-browser-selenium,代码行数:3,代码来源:utils.py


示例17: __init__

    def __init__(self, remote_server_addr, keep_alive=False, resolve_ip=True):
        # Attempt to resolve the hostname and get an IP address.
        self.keep_alive = keep_alive
        parsed_url = parse.urlparse(remote_server_addr)
        addr = parsed_url.hostname
        if parsed_url.hostname and resolve_ip:
            port = parsed_url.port or None
            if parsed_url.scheme == "https":
                ip = parsed_url.hostname
            elif port and not common_utils.is_connectable(port, parsed_url.hostname):
                ip = None
                LOGGER.info('Could not connect to port {} on host '
                            '{}'.format(port, parsed_url.hostname))
            else:
                ip = common_utils.find_connectable_ip(parsed_url.hostname,
                                                      port=port)
            if ip:
                netloc = ip
                addr = netloc
                if parsed_url.port:
                    netloc = common_utils.join_host_port(netloc,
                                                         parsed_url.port)
                if parsed_url.username:
                    auth = parsed_url.username
                    if parsed_url.password:
                        auth += ':%s' % parsed_url.password
                    netloc = '%[email protected]%s' % (auth, netloc)
                remote_server_addr = parse.urlunparse(
                    (parsed_url.scheme, netloc, parsed_url.path,
                     parsed_url.params, parsed_url.query, parsed_url.fragment))
            else:
                LOGGER.info('Could not get IP address for host: %s' %
                            parsed_url.hostname)

        self._url = remote_server_addr
        if keep_alive:
            self._conn = httplib.HTTPConnection(
                str(addr), str(parsed_url.port), timeout=self._timeout)

        self._commands = {
            Command.STATUS: ('GET', '/status'),
            Command.NEW_SESSION: ('POST', '/session'),
            Command.GET_ALL_SESSIONS: ('GET', '/sessions'),
            Command.QUIT: ('DELETE', '/session/$sessionId'),
            Command.GET_CURRENT_WINDOW_HANDLE:
                ('GET', '/session/$sessionId/window_handle'),
            Command.W3C_GET_CURRENT_WINDOW_HANDLE:
                ('GET', '/session/$sessionId/window'),
            Command.GET_WINDOW_HANDLES:
                ('GET', '/session/$sessionId/window_handles'),
            Command.W3C_GET_WINDOW_HANDLES:
                ('GET', '/session/$sessionId/window/handles'),
            Command.GET: ('POST', '/session/$sessionId/url'),
            Command.GO_FORWARD: ('POST', '/session/$sessionId/forward'),
            Command.GO_BACK: ('POST', '/session/$sessionId/back'),
            Command.REFRESH: ('POST', '/session/$sessionId/refresh'),
            Command.EXECUTE_SCRIPT: ('POST', '/session/$sessionId/execute'),
            Command.W3C_EXECUTE_SCRIPT:
                ('POST', '/session/$sessionId/execute/sync'),
            Command.W3C_EXECUTE_SCRIPT_ASYNC:
                ('POST', '/session/$sessionId/execute/async'),
            Command.GET_CURRENT_URL: ('GET', '/session/$sessionId/url'),
            Command.GET_TITLE: ('GET', '/session/$sessionId/title'),
            Command.GET_PAGE_SOURCE: ('GET', '/session/$sessionId/source'),
            Command.SCREENSHOT: ('GET', '/session/$sessionId/screenshot'),
            Command.ELEMENT_SCREENSHOT: ('GET', '/session/$sessionId/element/$id/screenshot'),
            Command.FIND_ELEMENT: ('POST', '/session/$sessionId/element'),
            Command.FIND_ELEMENTS: ('POST', '/session/$sessionId/elements'),
            Command.W3C_GET_ACTIVE_ELEMENT: ('GET', '/session/$sessionId/element/active'),
            Command.GET_ACTIVE_ELEMENT:
                ('POST', '/session/$sessionId/element/active'),
            Command.FIND_CHILD_ELEMENT:
                ('POST', '/session/$sessionId/element/$id/element'),
            Command.FIND_CHILD_ELEMENTS:
                ('POST', '/session/$sessionId/element/$id/elements'),
            Command.CLICK_ELEMENT: ('POST', '/session/$sessionId/element/$id/click'),
            Command.CLEAR_ELEMENT: ('POST', '/session/$sessionId/element/$id/clear'),
            Command.SUBMIT_ELEMENT: ('POST', '/session/$sessionId/element/$id/submit'),
            Command.GET_ELEMENT_TEXT: ('GET', '/session/$sessionId/element/$id/text'),
            Command.SEND_KEYS_TO_ELEMENT:
                ('POST', '/session/$sessionId/element/$id/value'),
            Command.SEND_KEYS_TO_ACTIVE_ELEMENT:
                ('POST', '/session/$sessionId/keys'),
            Command.UPLOAD_FILE: ('POST', "/session/$sessionId/file"),
            Command.GET_ELEMENT_VALUE:
                ('GET', '/session/$sessionId/element/$id/value'),
            Command.GET_ELEMENT_TAG_NAME:
                ('GET', '/session/$sessionId/element/$id/name'),
            Command.IS_ELEMENT_SELECTED:
                ('GET', '/session/$sessionId/element/$id/selected'),
            Command.SET_ELEMENT_SELECTED:
                ('POST', '/session/$sessionId/element/$id/selected'),
            Command.IS_ELEMENT_ENABLED:
                ('GET', '/session/$sessionId/element/$id/enabled'),
            Command.IS_ELEMENT_DISPLAYED:
                ('GET', '/session/$sessionId/element/$id/displayed'),
            Command.GET_ELEMENT_LOCATION:
                ('GET', '/session/$sessionId/element/$id/location'),
            Command.GET_ELEMENT_LOCATION_ONCE_SCROLLED_INTO_VIEW:
                ('GET', '/session/$sessionId/element/$id/location_in_view'),
#.........这里部分代码省略.........
开发者ID:nirinium,项目名称:PyAlarm,代码行数:101,代码来源:remote_connection.py


示例18: is_connectable

 def is_connectable(self):
     return utils.is_connectable(self.port)
开发者ID:292388900,项目名称:selenium,代码行数:2,代码来源:service.py


示例19: is_connectable

 def is_connectable(self):
     """Trys to connect to the extension but do not retrieve context."""
     utils.is_connectable(self.profile.port)
开发者ID:AlexGisi,项目名称:trusty-helper,代码行数:3,代码来源:extension_connection.py



注:本文中的selenium.webdriver.common.utils.is_connectable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python firefox_profile.FirefoxProfile类代码示例发布时间:2022-05-27
下一篇:
Python utils.free_port函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap