macos - Python 2.7 - 使用 Xvfb 进行 Selenium headless 测试不起作用

标签 macos python-2.7 selenium-webdriver

请注意,我已经查看了以下来源:

easyprocess.EasyProcessCheckInstalledError: cmd=['Xvfb', '-help'] OSError=[Errno 2] No such file or directory

How do I run Selenium in Xvfb?

这并没有解决我的问题。

我在用:

  • Python 2.7
  • Selenium 3.0.2
  • xvfbwrapper 0.2.9
  • PyVirtualDisplay 0.2.1

  • 在 Mac OSX El Capitan (10.11.6 (15G1108)) 上运行

    我收到以下错误(与上述链接中的错误相同):
    Traceback (most recent call last):
      File "/Users/user/Desktop/test.py", line 50, in <module>
        display = Display(visible=0, size=(800, 600))
      File "/Library/Python/2.7/site-packages/pyvirtualdisplay/display.py", line 34, in __init__
        self._obj = self.display_class(
      File "/Library/Python/2.7/site-packages/pyvirtualdisplay/display.py", line 52, in display_class
        cls.check_installed()
      File "/Library/Python/2.7/site-packages/pyvirtualdisplay/xvfb.py", line 38, in check_installed
        ubuntu_package=PACKAGE).check_installed()
      File "/Library/Python/2.7/site-packages/easyprocess/__init__.py", line 180, in check_installed
        raise EasyProcessCheckInstalledError(self)
    EasyProcessCheckInstalledError: cmd=['Xvfb', '-help']
    OSError=[Errno 2] No such file or directory
    Program install error! 
    

    我知道我也安装了 Xvfb:
    Xvfb -help
    use: X [:<display>] [option]
    -a #                   default pointer acceleration (factor)
    -ac                    disable access control restrictions
    -audit int             set audit trail level
    -auth file             select authorization file
    -br                    create root window with black background
    +bs                    enable any backing store support
    -bs                    disable any backing store support
    -c                     turns off key-click
    ...
    -pixdepths list-of-int support given pixmap depths
    +/-render          turn on/off RENDER extension support(default on)
    -linebias n            adjust thin line pixelization
    -blackpixel n          pixel value for black
    -whitepixel n          pixel value for white
    -fbdir directory       put framebuffers in mmap'ed files in directory
    -shmem                 put framebuffers in shared memory
    

    如果 pip install 在不同的目录中寻找 xvfb,将不胜感激有关如何重定向它正在查找的位置的一些指导。

    这是我的代码:
    from easyprocess import EasyProcess
    from pyvirtualdisplay import Display
    from selenium import webdriver
    
    display = Display(visible=0, size=(800, 600))
    display.start()
    
    # now Firefox will run in a virtual display. 
    # you will not see the browser.
    browser = webdriver.Firefox()
    browser.get('http://www.google.com')
    print browser.title
    browser.quit()
    
    display.stop()
    

    我已经完成了无数的 pip 安装和谷歌搜索,到目前为止没有任何帮助,最终的最终目标是拥有一个能够处理下载的 headless 自动化,这是 PhantomJS 无法做到的。在该主题上的任何帮助也将不胜感激。

    最佳答案

    我不明白为什么你不能在 osx 中使用它,我过去已经这样做了。但我有一个更好的解决方案。为什么不用docker + VNC .安装您选择的任何浏览器并在后台运行所有内容
    优势:
    1.一切都在后台运行。
    2. 使用 VNC 网页 View 在浏览器中监控执行情况
    3. 为并行执行启动任意数量的容器。

    关于macos - Python 2.7 - 使用 Xvfb 进行 Selenium headless 测试不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41205673/

    相关文章:

    python - vlc mac python 绑定(bind)无视频输出

    mysql - Python 中多表删除的正确 MySQL 查询

    javascript - 如何使用 selenium 获取所有元素的直接子元素和 css 选择器?

    macos - osx-在Appstore上载Mac App时无效的二进制文件

    c++ - 将 SDL2 与 Xcode 一起使用时出现 AddInstanceForFactory 和 HALC_ShellDriverPlugIn 错误?

    python - 将表情符号添加到 AFINN 库以进行情感分析

    Python 脚本不通过命令行运行

    python - 使用 Selenium for Python 从 <table> 中迭代读取特定元素

    selenium - 我可以使用自定义标签创建 XPath 吗?

    windows - 创建音频插件 UI 的 "best"方法是什么,该插件既是音频单元又是适用于 OS X 和 Windows 的 VST?