Selenium 在服务器上无法正常工作
Selenium does not work correctly on server
我有一个 Selenium 脚本,它在个人电脑和服务器上都能正常工作。几天前它停在服务器上,但我仍然没有弄清楚出了什么问题。我将 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 中。但是,我仍然无法 运行 我的代码。奇怪的是代码 运行 在 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:显示“: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
谢谢
你需要先像这样设置属性
System.setProperty("webdriver.firefox.marionette", getRootDir()+ "/src/main/java/configuration/geckodriver");
其中 getRootDir() 是绝对路径
然后创建驱动程序
driver = new FirefoxDriver();
问题已解决。我是 运行ning selenium headless,即使我设置了 DISPLAY=:1 它也无法正常工作。后来我改成了
export DISPLAY=:99
它又开始工作了。我怀疑我有一些未暂停的进程,他们阻止了我的显示。通过检查我的进程,我有许多待处理的 Firefox 进程。全部杀光后。我的代码 运行 在 Selenium 2.53.5 和 Firefox 45 上没有任何问题。
因此,我建议如果您的代码之前运行正常,但突然您的 selenium 停止运行,请通过以下方式检查您的显示:
export DISPLAY=:1
firefox
并且如果出现此错误:
Maximum number of clients reachedError: cannot open display: :1 selenium
同时适用于:
export DISPLAY=:99
firefox
您应该检查正在使用您的 DISPLAY 1 的暂停进程。
希望对你有所帮助
我有一个 Selenium 脚本,它在个人电脑和服务器上都能正常工作。几天前它停在服务器上,但我仍然没有弄清楚出了什么问题。我将 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 中。但是,我仍然无法 运行 我的代码。奇怪的是代码 运行 在 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:显示“: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
谢谢
你需要先像这样设置属性
System.setProperty("webdriver.firefox.marionette", getRootDir()+ "/src/main/java/configuration/geckodriver");
其中 getRootDir() 是绝对路径
然后创建驱动程序
driver = new FirefoxDriver();
问题已解决。我是 运行ning selenium headless,即使我设置了 DISPLAY=:1 它也无法正常工作。后来我改成了
export DISPLAY=:99
它又开始工作了。我怀疑我有一些未暂停的进程,他们阻止了我的显示。通过检查我的进程,我有许多待处理的 Firefox 进程。全部杀光后。我的代码 运行 在 Selenium 2.53.5 和 Firefox 45 上没有任何问题。
因此,我建议如果您的代码之前运行正常,但突然您的 selenium 停止运行,请通过以下方式检查您的显示:
export DISPLAY=:1
firefox
并且如果出现此错误:
Maximum number of clients reachedError: cannot open display: :1 selenium
同时适用于:
export DISPLAY=:99
firefox
您应该检查正在使用您的 DISPLAY 1 的暂停进程。
希望对你有所帮助