selenium/standalone-chrome 使用 selenium 4.0.0 return DNS 错误

selenium/standalone-chrome with selenium 4.0.0 return DNS ERROR

配置:Python3.10/selenium 3.141.0/selenium/standalone-chrome:最新作品!

但是

当我将 selenium 版本更改为 4.0.0 时: 配置:Python3.10/selenium 4.0.0/selenium/standalone-chrome:latest

服务器 return 当我尝试使用 remoteWebDriver 和 selenium 4.0.0 时出现 DNS 错误

Chrome 选项:

opt = Options()
        opt.add_argument('--disable-popup-blocking')
        opt.add_argument('--no-sandbox')
        opt.add_argument("--window-size=1920,1080")
        opt.add_argument("--start-maximized")alse)
        opt.headless = True

RemoteDrvcall:

self.wd = webdriver.Remote("http://chrome:4444/wd/hub", options=opt)

日志:

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f5f238b9ff0>
response = {'status': [13, 'unknown error'], 'value': '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/ht...d, 03 Nov 2021 21:47:30 GMT by CICD_External (squid/3.5.27)</p>\n<!-- ERR_DNS_FAIL -->\n</div>\n</body></html>'}

    def check_response(self, response: Dict[str, Any]) -> None:
        """
        Checks that a JSON response from the WebDriver does not have an error.
    
        :Args:
         - response - The JSON response from the WebDriver server as a dictionary
           object.
    
        :Raises: If the response contains an error message.
        """
        status = response.get('status', None)
        if not status or status == ErrorCode.SUCCESS:
            return
        value = None
        message = response.get("message", "")
        screen: str = response.get("screen", "")
        stacktrace = None
        if isinstance(status, int):
            value_json = response.get('value', None)
            if value_json and isinstance(value_json, str):
                import json
                try:
                    value = json.loads(value_json)
                    if len(value.keys()) == 1:
                        value = value['value']
                    status = value.get('error', None)
                    if not status:
                        status = value.get("status", ErrorCode.UNKNOWN_ERROR)
                        message = value.get("value") or value.get("message")
                        if not isinstance(message, str):
                            value = message
                            message = message.get('message')
                    else:
                        message = value.get('message', None)
                except ValueError:
                    pass
    
        exception_class: Type[WebDriverException]
        if status in ErrorCode.NO_SUCH_ELEMENT:
            exception_class = NoSuchElementException
        elif status in ErrorCode.NO_SUCH_FRAME:
            exception_class = NoSuchFrameException
        elif status in ErrorCode.NO_SUCH_WINDOW:
            exception_class = NoSuchWindowException
        elif status in ErrorCode.STALE_ELEMENT_REFERENCE:
            exception_class = StaleElementReferenceException
        elif status in ErrorCode.ELEMENT_NOT_VISIBLE:
            exception_class = ElementNotVisibleException
        elif status in ErrorCode.INVALID_ELEMENT_STATE:
            exception_class = InvalidElementStateException
        elif status in ErrorCode.INVALID_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR \
                or status in ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER:
            exception_class = InvalidSelectorException
        elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
            exception_class = ElementNotSelectableException
        elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
            exception_class = ElementNotInteractableException
        elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
            exception_class = InvalidCookieDomainException
        elif status in ErrorCode.UNABLE_TO_SET_COOKIE:
            exception_class = UnableToSetCookieException
        elif status in ErrorCode.TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.SCRIPT_TIMEOUT:
            exception_class = TimeoutException
        elif status in ErrorCode.UNKNOWN_ERROR:
            exception_class = WebDriverException
        elif status in ErrorCode.UNEXPECTED_ALERT_OPEN:
            exception_class = UnexpectedAlertPresentException
        elif status in ErrorCode.NO_ALERT_OPEN:
            exception_class = NoAlertPresentException
        elif status in ErrorCode.IME_NOT_AVAILABLE:
            exception_class = ImeNotAvailableException
        elif status in ErrorCode.IME_ENGINE_ACTIVATION_FAILED:
            exception_class = ImeActivationFailedException
        elif status in ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS:
            exception_class = MoveTargetOutOfBoundsException
        elif status in ErrorCode.JAVASCRIPT_ERROR:
            exception_class = JavascriptException
        elif status in ErrorCode.SESSION_NOT_CREATED:
            exception_class = SessionNotCreatedException
        elif status in ErrorCode.INVALID_ARGUMENT:
            exception_class = InvalidArgumentException
        elif status in ErrorCode.NO_SUCH_COOKIE:
            exception_class = NoSuchCookieException
        elif status in ErrorCode.UNABLE_TO_CAPTURE_SCREEN:
            exception_class = ScreenshotException
        elif status in ErrorCode.ELEMENT_CLICK_INTERCEPTED:
            exception_class = ElementClickInterceptedException
        elif status in ErrorCode.INSECURE_CERTIFICATE:
            exception_class = InsecureCertificateException
        elif status in ErrorCode.INVALID_COORDINATES:
            exception_class = InvalidCoordinatesException
        elif status in ErrorCode.INVALID_SESSION_ID:
            exception_class = InvalidSessionIdException
        elif status in ErrorCode.UNKNOWN_METHOD:
            exception_class = UnknownMethodException
        else:
            exception_class = WebDriverException
        if not value:
            value = response['value']
        if isinstance(value, str):
>           raise exception_class(value)
E           selenium.common.exceptions.WebDriverException: Message: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
E           <html><head>
E           <meta type="copyright" content="Copyright (C) 1996-2017 The Squid Software Foundation and contributors">
E           <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
E           <title>ERROR: The requested URL could not be retrieved</title>
E           <style type="text/css"><!-- 
E            /*
E            * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
E            *
E            * Squid software is distributed under GPLv2+ license and includes
E            * contributions from numerous individuals and organizations.
E            * Please see the COPYING and CONTRIBUTORS files for details.
E            */
E           
E           /*
E            Stylesheet for Squid Error pages
E            Adapted from design by Free CSS Templates
E            http://www.freecsstemplates.org
E            Released for free under a Creative Commons Attribution 2.5 License
E           */
E           
E           /* Page basics */
E           * {
E               font-family: verdana, sans-serif;
E           }
E           
E           html body {
E               margin: 0;
E               padding: 0;
E               background: #efefef;
E               font-size: 12px;
E               color: #1e1e1e;
E           }
E           
E           /* Page displayed title area */
E           #titles {
E               margin-left: 15px;
E               padding: 10px;
E               padding-left: 100px;
E               background: url('/squid-internal-static/icons/SN.png') no-repeat left;
E           }
E           
E           /* initial title */
E           #titles h1 {
E               color: #000000;
E           }
E           #titles h2 {
E               color: #000000;
E           }
E           
E           /* special event: FTP success page titles */
E           #titles ftpsuccess {
E               background-color:#00ff00;
E               width:100%;
E           }
E           
E           /* Page displayed body content area */
E           #content {
E               padding: 10px;
E               background: #ffffff;
E           }
E           
E           /* General text */
E           p {
E           }
E           
E           /* error brief description */
E           #error p {
E           }
E           
E           /* some data which may have caused the problem */
E           #data {
E           }
E           
E           /* the error message received from the system or other software */
E           #sysmsg {
E           }
E           
E           pre {
E               font-family:sans-serif;
E           }
E           
E           /* special event: FTP / Gopher directory listing */
E           #dirmsg {
E               font-family: courier;
E               color: black;
E               font-size: 10pt;
E           }
E           #dirlisting {
E               margin-left: 2%;
E               margin-right: 2%;
E           }
E           #dirlisting tr.entry td.icon,td.filename,td.size,td.date {
E               border-bottom: groove;
E           }
E           #dirlisting td.size {
E               width: 50px;
E               text-align: right;
E               padding-right: 5px;
E           }
E           
E           /* horizontal lines */
E           hr {
E               margin: 0;
E           }
E           
E           /* page displayed footer area */
E           #footer {
E               font-size: 9px;
E               padding-left: 10px;
E           }
E           
E           
E           body
E           :lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; }
E           :lang(he) { direction: rtl; }
E            --></style>
E           </head><body id=ERR_DNS_FAIL>
E           <div id="titles">
E           <h1>ERROR</h1>
E           <h2>The requested URL could not be retrieved</h2>
E           </div>
E           <hr>
E           
E           <div id="content">
E           <p>The following error was encountered while trying to retrieve the URL: <a href="http://chrome:4444/wd/hub/session">http://chrome:4444/wd/hub/session</a></p>
E           
E           <blockquote id="error">
E           <p><b>Unable to determine IP address from host name <q>chrome</q></b></p>
E           </blockquote>
E           
E           <p>The DNS server returned:</p>
E           <blockquote id="data">
E           <pre>Server Failure: The name server was unable to process this query.</pre>
E           </blockquote>
E           
E           <p>This means that the cache was not able to resolve the hostname presented in the URL. Check if the address is correct.</p

结果会话未创建且构建失败(仅适用于 selenium 4.0.0)

如有任何想法,我将不胜感激

尝试:

self.wd = webdriver.Remote("http://chrome:4444", options=opt)

而不是

self.wd = webdriver.Remote("http://chrome:4444/wd/hub", options=opt)

他们改变了网格的界面。

谢谢@pcalkins。已在评论中回答

存在issue:selenium 4.0.0 + gitlab


在gitlab-ci.yml重新定义no_export变量

  • export no_proxy="为 SELENIUM STANDALONE 添加您的别名(例如 chrome)"

    services:
      - name: selenium/standalone-chrome:98.0
        alias: chrome