selenium服务器,selenium客户端,在UBUNTU GUI服务器上

时间:2016-09-05 15:28:47

标签: java python selenium ubuntu ssh

我有VPS ubuntu 14.04 LTS并安装了桌面软件包,这意味着我可以从ssh -X会话启动firefox。 为了进行测试,我从服务器启动了selenium独立服务器jar (selenium-server-standalone-3.0.0-beta3.jar) 启动后,在另一个ssh会话中,我只需输入python命令:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

然后,按照说明进行操作 http://selenium-python.readthedocs.io/getting-started.html#using-selenium-with-remote-webdriver,我输入:

driver = webdriver.Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=DesiredCapabilities.FIREFOX)

45秒后,我在服务器窗口和客户端窗口都有很多错误。 这是主要错误:

  

引起:org.openqa.selenium.firefox.NotConnectedException:45000 ms后无法在端口7055上连接到主机127.0.0.1。 Firefox控制台输出:       错误:GDK_BACKEND与可用显示不匹配

我看到一些人有同样的问题,但即使使用最新的java和selenium版本,我仍然遇到了这个问题。 提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

您似乎正在尝试selenium 3最新的Firefox版本。要使用selenium 3支持最新的Firefox,需要download latest geckodriver executable from this link并在任何位置将其解压缩到您的系统中。

现在运行selenium-server-standalone-3.0.0-beta3.jar使用以下命令: -

java -jar selenium-server-standalone-3.0.0-beta3.jar -Dwebdriver.gecko.driver = "path/to/downloaded geckodriver"

现在您需要将marionette属性设置为true以支持使用selenium 3的最新Firefox,如下所示: -

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX

# Tell the Python bindings to use Marionette.
caps["marionette"] = True

driver = webdriver.Remote(command_executor = 'http://127.0.0.1:4444/wd/hub', desired_capabilities = caps)

注意: - 更多information about marionette follow this Mozilla official page