0

Below is the code am writing in FreeBSD. Before this code, I did

pkg install xorg-vfbserver

but after this I don't know which environment variable to set. Like in Ubuntu you have to do like this before using this program

apt-get install xvfb
export DISPLAY = :1


In FreeBSD, what is the environment variable to set ? I read USES = DISPLAY but I couldn't understand as there isn't much of information about it. And because of that the Firefox starts and closes



from pyvirtualdisplay import Display
from selenium import webdriver

try:
        display = Display(visible=0, size=(800,600))
        display.start()
except:
        print "no virtual display found"


driver = webdriver.Firefox()

driver.get('www.google.com')

driver.close()
Pang
  • 9,564
  • 146
  • 81
  • 122
Tahseen
  • 1,027
  • 1
  • 12
  • 32
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Jan 05 '16 at 15:09

1 Answers1

1

Installing X Virtual Frame

 sudo pkg install xorg-vfbserver
 sudo pkg install xkeyboard-config
 sudo pkg install xkbcomp
 sudo pkg instal x11-fonts/xorg-fonts

Firefox installation and machine-id generation

sudo pkg install firefox
dbus-uuidgen > machine-id
sudo mv machine-id /etc/

Depening on shell below are for bash. Better it in .bashrc or .cshrc file so that whenever you start a new terminal environment variable DISPLAY is set

export DISPLAY=:1

and in case of tcsh. Sometimes tcsh is default shell in FreeBSD

setenv DISPLAY :1

Start Xvfb and send it in background

nohup Xvfb :1 -screen 0 800x600x16 &

Now you don't even need to use pyvirtualdisplay in python. Just use webdriver.

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('http://www.google.com')
driver.close()
Tahseen
  • 1,027
  • 1
  • 12
  • 32