简体   繁体   English

是否需要在Linux机器上为无头firefox浏览器设置DISPLAY

[英]Is it required to set the DISPLAY for headless firefox browser on linux machine

I want to run the headless browser and below is the code for same. 我想运行无头浏览器,下面是相同的代码。 However when i ran it. 但是,当我运行它。 it shows "Error: no DISPLAY environment variable specified" 它显示“错误:未指定DISPLAY环境变量”

try {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.log.driver", "INFO");
profile.setPreference("webdriver.log.file", targetDir + File.separator + "firefoxSeleniumServer.log");
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv;text/plain");
if(platform.equalsIgnoreCase("linux")) {
DesiredCapabilities desiredCap = DesiredCapabilities.firefox();
profile.setPreference("browser.download.dir",System.getProperty("user.dir")+ File.separator + "target");
System.setProperty("webdriver.gecko.driver", "/test/geckodriver/geckodriver");
System.setProperty("webdriver.firefox.bin","/usr/bin/firefox/firefox");
desiredCap.setCapability("headless", true);
driver = new FirefoxDriver();
}

However when i set the display it shows unable to open firefox on DISPLAY:99 但是,当我设置显示器时,它显示无法在DISPLAY:99上打开Firefox

Also i tried setting the xvfb as well. 我也尝试设置xvfb。 But that also did not work. 但这也不起作用。

As i am using gekco driver here, do i need to do some more configurations. 当我在这里使用gekco驱动程序时,是否需要做更多配置。

I think you are supposed to provide the DesiredCapabilities object as a parameter to the FirefoxDriver constructor: 我认为您应该将DesiredCapabilities对象作为参数提供给FirefoxDriver构造函数:

References 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firefox Headless 在无头 redhat linux 机器上崩溃 - Firefox headless crashing on headless redhat linux machine 在 linux 机器上运行时,Click 在 Firefox Headless 中不起作用 - Click is not working in firefox headless while running in linux machine 无法使用 Selenium Webdriver java 在 Linux 机器上运行 Headless Chrome 浏览器 - Unable to run Headless Chrome Browser on Linux Machine using Selenium Webdriver java 硒-在无头浏览器中设置标头 - Selenium - set headers in headless browser 使用Chrome无头浏览器实现自动化,每次都需要OTP - Automating with Chrome headless browser, required OTP everytime jFreechart不在Linux机器中显示 - jFreechart not display in linux machine Linux无头机修改文件时触发java jar文件 - Trigger a java jar file when a file is modified in the Linux headless machine 在浏览器中显示客户端计算机的日期和时间以及时区 - Display client machine date and time with timezone in browser 如何在无头远程 Linux 服务器上运行应用程序并查看本地 Windows 机器上的 UI - How to run an application on headless remote Linux server and see the UI on my local Windows machine Linux机器中堆使用所需的jmap命令的替代 - Alternate of jmap command required in Linux machine for heap usage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM