Forums

Selenium with Visible Display

I am able to get Selenium to run when the display is hidden, as in

from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()

However, I can't get a visible display when I use this

from pyvirtualdisplay import Display
display = Display(visible=1, size=(800, 600))
display.start()

I get an error

Traceback (most recent call last):                                                                                                                                                                                                         
  File "/home/sjones345/Selenium/test_selenium.py", line 6, in <module>                                                                                                                                                                    
    display = Display(visible=1, size=(800, 600))                                                                                                                                                                                          
  File "/usr/local/lib/python2.7/dist-packages/pyvirtualdisplay/display.py", line 33, in __init__                                                                                                                                          
    self._obj = self.display_class(                                                                                                                                                                                                        
  File "/usr/local/lib/python2.7/dist-packages/pyvirtualdisplay/display.py", line 50, in display_class                                                                                                                                     
    cls.check_installed()                                                                                                                                                                                                                  
  File "/usr/local/lib/python2.7/dist-packages/pyvirtualdisplay/xephyr.py", line 29, in check_installed                                                                                                                                    
    ubuntu_package=PACKAGE).check_installed()                                                                                                                                                                                              
  File "/usr/local/lib/python2.7/dist-packages/easyprocess/__init__.py", line 209, in check_installed                                                                                                                                      
    raise EasyProcessCheckInstalledError(self)                                                                                                                                                                                             
easyprocess.EasyProcessCheckInstalledError: cmd=['Xephyr', '-help']                                                                                                                                                                        
OSError=[Errno 2] No such file or directory                                                                                                                                                                                                
Program install error!                                                                                                                                                                                                                     
You can install it in terminal:                                                                                                                                                                                                            
sudo apt-get install xephyr

When I go to sudo install xephyr as the error suggests, I get

20:36 ~ $ sudo apt-get install xephyr                                                                                                                                                                                                      
sudo: unknown user: root
sudo: unable to initialize policy plugin

I am just trying PythonAnywhere out for the first time at the "Beginner" level so I'm wondering if that is why I can't install or if it's something else.

Any help? Thanks!

What are you expecting when you set 'visible'?

Anyway, you could try:

pip install xephyr --user

(that's hyphen hyphen 'user', NOT your user name)

HTH Jim

Installing xephyr will not change anything. There is no screen for your app to be visible on, so there's no way for it to render.

Ah, that makes sense. Thanks!