【问题标题】:Selenium does not work correctly on serverSelenium 在服务器上无法正常工作
【发布时间】:2017-06-02 14:14:52
【问题描述】:

我有一个带有 Selenium 的脚本,它在 pc 和服务器上都可以正常工作。几天前它停在服务器上,但我仍然没有弄清楚出了什么问题。我将 Firefox (41.0.2) 和 Selenium (2.53.5) 都设置为与 PC 和本地相似。

通过运行:

from selenium import webdriver

browser = webdriver.Firefox()

使用当前版本,我遇到此错误:

selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

我应该提到我使用设置 DISPLAY:=1; 运行我的代码

我决定将 selenium 升级到 3.0.2,但我遇到了:

IOError: [Errno 13] Permission denied: 'geckodriver.log'

根据其他遇到此问题的人的建议,我下载了 geckidriver 并将其放在 /usr/local/bin 中。但是,我仍然无法运行我的代码。奇怪的是代码在电脑上运行没有任何问题!

有什么意见或建议吗?

这是 geckodriver.log 的输出:

(firefox:94561): GConf-WARNING **: Client failed to connect to the D-BUS  daemon:
/usr/bin/dbus-launch terminated abnormally without any error message
1484733755568   geckodriver     INFO    Listening on 127.0.0.1:35823
1484733756567   mozprofile::profile     INFO    Using profile path     /tmp/rust_mozprofile.UiIxs53qoUs1
1484733756568   geckodriver::marionette INFO    Starting browser /usr/bin/firefox
1484733756573   geckodriver::marionette INFO    Connecting to Marionette on localhost:44907

(process:95171): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed

Xlib:显示“:1”上缺少扩展名“RANDR”。

(firefox:95171): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
/usr/bin/dbus-launch terminated abnormally without any error message

(firefox:95171): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
/usr/bin/dbus-launch terminated abnormally without any error message

(firefox:95171): GConf-WARNING **: Client failed to connect to the D-BUS daemon:
/usr/bin/dbus-launch terminated abnormally without any error message

  (firefox:95171): GConf-WARNING **: Client failed to connect to the  D-BUS daemon:
 /usr/bin/dbus-launch terminated abnormally without any error message

谢谢

【问题讨论】:

  • 这是我的 geckodriver.log:

标签: python-2.7 selenium firefox geckodriver


【解决方案1】:

你需要先像这样设置属性

System.setProperty("webdriver.firefox.marionette", getRootDir()+ "/src/main/java/configuration/geckodriver");

其中 getRootDir() 是绝对路径

然后创建驱动程序

driver = new FirefoxDriver();

【讨论】:

    【解决方案2】:

    问题解决了。我正在无头运行 selenium,即使我设置了 DISPLAY=:1 它也无法正常工作。后来我改成

    export DISPLAY=:99
    

    它又开始工作了。我怀疑我有一些未暂停的进程,他们阻止了我的 DISPLAY。通过检查我的进程,我有许多待处理的 Firefox 进程。全部杀光之后。我的代码在 Selenium 2.53.5 和 Firefox 45 上运行没有任何问题。

    所以,我建议如果您的代码之前正常工作,突然您的 selenium 停止工作,请通过以下方式检查您的 DISPLAY:

    export DISPLAY=:1
    firefox
    

    如果出现此错误:

    Maximum number of clients reachedError: cannot open display: :1 selenium
    

    同时它适用于:

    export DISPLAY=:99
    firefox
    

    您应该检查正在使用您的 DISPLAY 1 的暂停进程。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2012-08-02
      • 1970-01-01
      • 2011-02-27
      • 2013-08-10
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 2022-12-18
      相关资源
      最近更新 更多