3

I develop a small app (in C#) which automatize a test on a website with Selenium. Everything is going well. But when I try the same app with "headless" browser the test doesn't work. I have an issue with the code below :

var emailTextBox = driver.FindElement(By.Id("j_username"));

OpenQA.Selenium.WebDriverException : 'The HTTP request to the remote WebDriver server for URL http://localhost:49309/session/d4416c4b-e674-468b-8d6e-6a8bfc9bdf1d/element timed out after 60 seconds.'

The same test works with a normal browser but not in headless mode, I try to use Firefox, Chrome, PhantomJS (all in headless) and it doesn't work...

Do you have an idea ?

My whole code is :

'''

using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;

namespace MacDo
{
    class Program
    {
        static void Main(string[] args)
        {
            var driverService = FirefoxDriverService.CreateDefaultService();
            driverService.HideCommandPromptWindow = true;

            var options = new FirefoxOptions();
            options.AddArguments("-headless");

            IWebDriver driver = new FirefoxDriver(driverService, options);
            driver.Url = "https://www.mcdonalds.fr/";
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10000);

            System.Threading.Thread.Sleep(2000);

            var seConnecter = driver.FindElement(By.Id("seconnecter"));
            seConnecter.Click();

            driver.Close();
            driver.Quit();

            Console.ReadKey();
        }
    }
}

'''

I use Firefox Browser 73.0.1 (32 bits) (-> I use Geckodriver version 0.26.0)

As said before, it works well, but not in headless mode...

Nounet
  • 63
  • 1
  • 6

1 Answers1

2

I had the same issue in past where script did not work in headless and I found out it was due to default resolution. You can try adding

options.addArguments("window-size=1920,1080");

Worth trying!

Viki
  • 157
  • 1
  • 3