I start a display with pyvirtualdisplay
before creating my WebDriver
instance. If I use Chrome, it works without any problem: Chrome shows up in the Xephyr instance that pyvirtualdisplay
creates. However, when I use Firefox, the Xephyr instance appears but Firefox shows up outside of it.
Here is code that fully reproduces the problem:
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import FirefoxBinary
import pyvirtualdisplay
binary = FirefoxBinary()
with pyvirtualdisplay.Display(visible=True):
if True: # Set to False to use Chrome...
driver = webdriver.Firefox(None, binary)
else:
driver = webdriver.Chrome()
driver.get("http://www.google.com")
driver.quit()
The code above is a minimal version of code that is more complex (which explains the seemingly useless FirefoxBinary()
).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…