I\'ve spent the last few days messing around with Selenium, Tor, and Firefox as a combination for multiple tasks. I\'ve managed to write a simple script in Python that takes
Or alternatively use a true headless browser, like Phantomjs which is light weighted and nicely integrated with selenium
from selenium import webdriver
driver=webdriver.PhantomJS('your pahtomjs exe file locaiton')
if finally find the answer:
First, of first do these:
Take care that you set fire fox drive path correctly.
And then:
sudo apt-add-repository ppa:mozillateam/firefox-next
sudo apt-get update
sudo apt-get install firefox xvfb
Xvfb :10 -ac &
export DISPLAY=:10
And at the end run this command to see that do we have any error in our implementation of not.
firefox
and if there no any output just click ctrl+c.
Ok, after that write this codes.
from selenium import webdriver
class FireFoxLoadTest:
def __init__(self):
# 1 - Load a fire fox web driver
self.driver = webdriver.Firefox()
def do_test(self, url):
# 2 - Start to check url on the fire fox browser
result = self.driver.get(url)
self.driver.quit()
return self.result
fire_fox = FireFoxLoadTest()
res = fire_fox.do_test('http://www.google.com')
print(res)
xvfb is a common way of doing this. Searching for "selenium xvfb" should find lots, such as:
You can set headless mode through webdriver.FirefoxOptions()
, just like you did with Chrome:
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.add_argument('headless')
driver = webdriver.Firefox(options=options)
P.S. If you use Selenium < 3.8.0, you have to replace webdriver.FirefoxOptions()
with webdriver.firefox.options.Options()
(see PR #5120).
Besides, use enviroment variable MOZ_HEADLESS
will do the same thing:
import os
from selenium import webdriver
os.environ['MOZ_HEADLESS'] = '1' # <- this line
driver = webdriver.Firefox()
There is progress being made on headless firefox.
From April 21st, 2017, https://adriftwith.me/coding/2017/04/21/headless-slimerjs-with-firefox/
tl;dr Firefox Nightly on Linux supports running SlimerJS headlessly.
More platforms and full headless Firefox are coming soon.