Selenium在服务器上无法正常运行

时间:2017-01-18 09:17:14

标签: python-2.7 selenium firefox geckodriver

我有一个Selenium的脚本,它正确地在pc和服务器上工作。几天前它停在了服务器上,但我还没弄清楚出了什么问题。我通过pc和本地设置Firefox(41.0.2)和Selenium(2.53.5)。

通过运行:

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中。但是,我仍然无法运行我的代码。奇怪的是,代码在pc上运行没有任何问题!

有任何建议或意见吗?

这是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:扩展" RANDR"显示屏上缺少":1"。

(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

谢谢

2 个答案:

答案 0 :(得分:1)

您需要首先像这样设置属性

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

其中getRootDir()是绝对路径

然后创建驱动程序

driver = new FirefoxDriver();

答案 1 :(得分:0)

问题解决了。我正在运行selenium headless甚至我设置了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的暂停进程。

我希望它可以提供帮助。

相关问题