0

I am following a Selenium tutorial where I am supposed to run Firefox in headless mode. This is followed by trying to get a URL. The problem is that when I run browser.get('https://www.google.com'), the page doesn't load as it would when I didn't use headless mode.

Here's the code if it helps


from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options

opts = Options()
opts.headless = True
assert opts.headless
browser = Firefox(options=opts)
browser.get('https://www.google.com')

Arif
  • 309
  • 3
  • 10

2 Answers2

1

Headless testing is a way of running browser UI tests without the head, which in this case means that there’s no browser UI, no GUI of any sorts. This is useful since when running tests, especially in a CI environment, there is nobody “watching” the visuals, so there is no need to have the extra overhead of the browser GUI.

https://blog.logrocket.com/introduction-to-headless-browser-testing-44b82310b27c/

rahul rai
  • 2,260
  • 1
  • 7
  • 17
0

Browser Automation

Browser automation have become an important part of how modern websites are built, tested, and deployed. Automation setups range from scripts to run on local machines to deployments in CI servers running Jenkins, CircleCI, TeamCity, Bamboo, GitLab, Buddy, Travis CI, Codeship, GoCD, Wercker, Semaphore, Nevercode, Spinnaker, Buildbot, etc as well as in the cloud. Browsers have long supported some level of automated control through third-party driver software.

@Potch in his article explains the idea of headless in simple words that, browsers are at their core a user interface to the web, and a graphical user interface in particular. This poses a few problems for automation. In some environments, there may be no graphical display available, or it may be desirable to not have the browser appear at all when being controlled. This has required tools like virtual display software in order to run properly, adding complexity.

Before the idea of came into practice, the best way to load webpages without displaying UI was PhantomJS, which is based on WebKit. It still remains as a valuable tool to be able to run automated browser tests in official browsers, and so it’s valuable to have a headless mode available.


Firefox in Headless Mode

In headless mode Firefox is run as normal, minus any visible UI components visible. Though not so useful for surfing the web, it comes into its own with automated testing.


References

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352