[英]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 参考
FirefoxDriver
. FirefoxDriver
的Javadoc 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.