I have a something like:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
class Gecko {
...
FirefoxBinary ffB = new FirefoxBinary();
ffB.setEnvironmentProperty("DISPLAY", ":10");
...
options.setBinary(ffB);
WebDriver driver = new FirefoxDriver(options);
Then I start a virtual frame buffer with:
Xvfb :10 -screen 0 1024x768x24 &
But when I run with Selenium:
java -cp .:selenium-server-standalone-3.5.0.jar Gecko
the following problem shows:
1508364524466 geckodriver::marionette INFO Starting browser /usr/bin/firefox with args ["-marionette"]
Error: GDK_BACKEND does not match available displays
Exception in thread "main" org.openqa.selenium.WebDriverException: connection refused
Which could be a possible cause? User permission? Firewall? The current box doesn't have any desktop environment installed.
If it says Error: GDK_BACKEND does not match available displays then install pyvirtualdisplay:
pip install pyvirtualdisplay selenium
You might need xvfb too:
sudo apt-get install xvfb
Then try adding this code:
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Full example:
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get('http://www.python.org')
browser.close()
display.stop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.