【问题标题】:'selenium.common.exceptions.WebDriverException: Message: u'chrome not reachable'selenium.common.exceptions.WebDriverException:消息:u'chrome 无法访问
【发布时间】:2015-03-23 07:03:20
【问题描述】:

我正在使用 webdriver 来配置路由器,但是当我运行脚本时:

from selenium import webdriver
self.driver = webdriver.Chrome()

打开chrome没有反应,然后引发异常:

chrome 无法访问。

我的电脑有两个网卡,当我禁止一个时,它工作得很好。
我不知道为什么,请帮忙!

【问题讨论】:

    标签: python selenium webdriver selenium-chromedriver


    【解决方案1】:

    在纯粹的情况下,“chrome 不可达”意味着 Chrome 二进制可以启动但调试端口不可达。

    调试端口由参数设置:--remote-debugging-port=12582

    就我而言,这是因为沙盒的一些问题:

    ps afvvx | grep chrome
    
    /opt/google/chrome/chrome --disable-background-networking --disable-client-side-phishing
    21026 pts/2    S+     0:00      0    47  6008   100  0.0  |           \_ cat
    21027 pts/2    S+     0:00      0    47  6008   100  0.0  |           \_ cat
    21029 pts/2    Z+     0:00      0     0     0     0  0.0  |           \_ [chrome-sandbox] <defunct>
    

    当我运行 /opt/google/chrome/chrome-sandbox

    # /opt/google/chrome/chrome-sandbox  -h
    The setuid sandbox provides API version 1, but you need 0
    Please read [https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment][1].
    
    close: Bad file descriptor
    Read on socketpair: Success
    

    从上面的网址我无法获得修复 SUID 沙盒的方法,但可以通过 Chrome arg --disable-setuid-sandbox(有时使用 --no-sandbox)将其关闭:

    import time
    from selenium import webdriver
    
    from xvfbwrapper import Xvfb
    
    vdisplay = Xvfb()
    vdisplay.start()
    
    from selenium.webdriver.chrome.options import Options
    chrome_options = Options()
    chrome_options.add_argument("--no-sandbox")
    chrome_options.add_argument("--disable-setuid-sandbox")
    
    driver = webdriver.Chrome('/usr/local/sbin/chromedriver', chrome_options=chrome_options)  # Optional argument, if not specified will search path.
    driver.get('http://www.google.com/xhtml');
    time.sleep(5) # Let the user actually see something!
    search_box = driver.find_element_by_name('q')
    search_box.send_keys('ChromeDriver')
    search_box.submit()
    time.sleep(5) # Let the user actually see something!
    driver.quit()
    
    vdisplay.stop()
    

    【讨论】:

      【解决方案2】:

      另一种情况是像 dbus-X11 这样的包没有安装:

      /opt/google/chrome/google-chrome --no-sandbox --disable-setuid-sandbox --disable-background-networking --disable-client-side-phishing-detection --disable-component-update --disable-default-apps --disable-hang-monitor --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-logging --ignore-certificate-errors --load-extension=/tmp/.com.google.Chrome.a0gQAp/internal --log-level=0 --metrics-recording-only --no-first-run --password-store=basic --remote-debugging-port=12512 --safebrowsing-disable-auto-update --safebrowsing-disable-download-protection --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.dgq4j1 data:,
      [39330:39330:0501/130308:ERROR:browser_main_loop.cc(185)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
      Xlib:  extension "RANDR" missing on display ":1070".
      Xlib:  extension "RANDR" missing on display ":1070".
      [39330:39330:0501/130308:ERROR:desktop_window_tree_host_x11.cc(830)] Not implemented reached in virtual void views::DesktopWindowTreeHostX11::InitModalType(ui::ModalType)
      
      (google-chrome:39330): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
      /usr/bin/dbus-launch terminated abnormally without any error message
      [39330:39353:0501/130308:ERROR:browser_gpu_channel_host_factory.cc(151)] Failed to create channel.
      

      只需安装它:

      apt-get install dbus-X11
      

      【讨论】:

        猜你喜欢
        • 2014-03-15
        • 1970-01-01
        • 2020-04-17
        • 1970-01-01
        • 2018-08-18
        • 2016-06-22
        • 2017-02-21
        • 1970-01-01
        • 2016-09-25
        相关资源
        最近更新 更多