Is it true that Selenium works only in headless mode in production? (Django)

Viewed 573

I have a Django view function:

def bypass_link(request, pk=None):
    instance = fields.objects.get(pk=pk)
    link = instance.quote
    options = webdriver.ChromeOptions()
    driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)

    driver.get(link)
    driver.find_element_by_id("butAgree").click()
    return redirect(link)

template:

<td data-label="Quote">
    <a href="{% url 'bypass_link' i.id %}" target="_blank">{{ i.link }}</a>
</td>

urls.py

from django.conf.urls import url 

url(r'^bypass_link/(?P<pk>\d+)/$', views.bypass_link, name="bypass_link"),

This opens two links when I click on the hyperlink. When I remove the return redirect(link), this shows the error on the page but the selenium window is working fine.

I just want to open the selenium window when clicking on the hyperlink.

Edits:

I changed the line to return redirect(index), this worked on local. But when I tried this on production, this shows an error. This error was solved if I run selenium in headless mode. But, I don't want to run in headless mode in production. Is it true that Selenium works only in headless mode in production?

3 Answers

Headless software (e.g. "headless Java" or "headless Linux",) is software capable of working on a device without a graphical user interface. ... The term "headless" is most often used when the ordinary version of the program requires that a graphics card or similar graphical interface device be present.

https://en.wikipedia.org/wiki/Headless_software

If by "production" you mean a remote server like a VPS or something, Then probably no you can not run a graphical web browser on the server it would have to be headless.

Solution Check if the issue persists for all links, give a simple link like google.com sometimes the issue may persist for sites with

  • Bad certificates can be resolved with --ignore-certificate-errors
  • Self signed certificate can be resolved with --enable-features=NetworkService

Alternatively you can opt to not go for headless browser in production and utilise browserstack or saucelabs. Cloud based continuously testing platform, most ideal for cross browser and cross platform testing

you can selenium headless mode in any kind of environment, it is one of the configurable feature in automation.

Related