[Python] Selenium and Pyvirutaldisplay not working together on Mac

Discussão em 'Python' iniciado por Stack, Fevereiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I've been using Selenium in conjunction with the python pyvirutaldisplay library on Linux to have the webdriver run entirely in the virtual display window. However the code doesn't behave as expected when used on a Mac machine. The basic case is as follows:

    from selenium import webdriver
    from pyvirutaldisplay import Display

    d = Display()
    d.start()
    driver = webdriver.Chrome()


    What happens on Linux, and what I expect to happen is that a virtual display is opened and then the webdriver is applied to it. However what happens on Mac is that the virtual display is created and then the webdriver is launched but not applied to the virtual display.

    I really don't know why this is happening. I'm not sure if it's because Mac GUI applications behave differently than on Linux so pyvirutaldisplay setting the "DISPLAY" environment variable and starting a Xvfb server isn't enough to apply the webdriver to the new display. I don't know and any help would be appreciated.

    If it helps the Mac in question is on OS: Ventura 13.5.2. Selenium version is: 4.4.2. Browser is Chromedriver 117.0.5938.88. I also have xquartz installed on the Mac and Xvfb added to the PATH.

    Thanks in advance!

    Continue reading...

Compartilhe esta Página