Selenium GeckoDriver failing with blank page

Viewed 46

I'm getting a blank page when trying to verify the driver url. I have this set up in debug logging mode. This is the FirefoxWebDriver.

UPDATE: If I take out all webdriver options then the tests work on a server but do not work in a Docker container.

FINAL UPDATE: Switched over to Chrome and found success, but with some important caveats.

   [TestMethod]               
    public void NavigatesToContainerSite()
    {  
        WebDriverWait webDriverWait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
       
        _driver.Navigate().GoToUrl("http://www.example.com:8083/"); 
        string url = _driver.Url;                        
        Assert.AreEqual("http://www.example.com:8083/", url);          
    }
   [ClassInitialize]
   public static void SetupOnce(TestContext context)
    {
        _options = new FirefoxOptions();
        Proxy p = new Proxy();        
        p.SocksProxy = proxy url;  
        p.SocksVersion = 5;      
        p.Kind = ProxyKind.Manual;
        _options.Proxy = p;
        
        _options.PageLoadStrategy = PageLoadStrategy.None;
        _options.LogLevel = FirefoxDriverLogLevel.Debug;
       
        _options.AddArguments("--no-sandbox", "--disable-software-rasterizer","--headless" ,"--whitelisted-ips=\"\"",
            "--disable-infobars","--disable-gpu","--disable-dev-shm-usage","--disable-extensions");           
        _driver = new FirefoxDriver(_options);            
   }

Here is the logging aspect of the request. If I just create a passing test that navigates to the url it seems to work but when I try to get something off the page (url, page elements) it throws exception.

Question: does the 200 OK indicate the driver.navigate succeeded or does it just mean the request for the webdriver session succeeded?

I just put the example.com url in this code example to hide my real url.

  "1662816403483\twebdriver::server\tDEBUG\t-> POST /session/b29b42e9-cef5-4ef3-a281-8aafb21ea8cc/url {\"url\":\"http://www.example.com:8083/?username=owen.charles\"}", 
    "1662816403484\tMarionette\tDEBUG\t0 -> [0,2,\"WebDriver:Navigate\",{\"url\":\"http://www.example.com:8083/"}]", 
    "1662816403487\tMarionette\tDEBUG\t0 <- [1,2,null,{\"value\":null}]", 
    "1662816403487\twebdriver::server\tDEBUG\t<- 200 OK {\"value\":null}", 
    "1662816403541\twebdriver::server\tDEBUG\t-> POST /session/b29b42e9-cef5-4ef3-a281-8aafb21ea8cc/url {\"url\":\"http://www.example.com:8083/"}", 
    "1662816403542\tMarionette\tDEBUG\t0 -> [0,3,\"WebDriver:Navigate\",{\"url\":\"http://www.example.com:8083/"}]", 
    "1662816403543\tMarionette\tDEBUG\t0 <- [1,3,null,{\"value\":null}]", 
    "1662816403543\twebdriver::server\tDEBUG\t<- 200 OK {\"value\":null}", 
    "1662816403580\twebdriver::server\tDEBUG\t-> GET /session/b29b42e9-cef5-4ef3-a281-8aafb21ea8cc/url ", 
    "1662816403581\tMarionette\tDEBUG\t0 -> [0,4,\"WebDriver:GetCurrentURL\",{}]", 
    "1662816403581\tMarionette\tDEBUG\t0 <- [1,4,null,{\"value\":\"about:blank\"}]", 
    "1662816403581\twebdriver::server\tDEBUG\t<- 200 OK {\"value\":\"about:blank\"}", 
    "1662816403657\twebdriver::server\tDEBUG\t-> DELETE /session/b29b42e9-cef5-4ef3-a281-8aafb21ea8cc ", 
    "1662816403658\tMarionette\tDEBUG\t0 -> [0,5,\"Marionette:Quit\",{\"flags\":[\"eForceQuit\"]}]", 
    "1662816403658\tMarionette\tINFO\tStopped listening on port 49197", 

This method doesn't produce an error:

[TestMethod]               
    public void NavigatesToContainerSite()
    {  
        WebDriverWait webDriverWait = new WebDriverWait(_driver, TimeSpan.FromSeconds(30));
        _driver.Navigate().GoToUrl("http://www.example.com:8083");              
        Assert.AreEqual("one", "one");          
    }
1 Answers

No one answered this but I did come up with a solution so I will just post it here. I had enough issues with the GeckoWebDriver that I switched to ChromeWebDriver. But the solution I arrived at may resolve the Gecko issue as well.

Steps I took:

  • Downloaded Chrome, major version 105

  • Incorporated ChromeWebDriver, major version 105 (these two have to match!)

  • Set two arguments when I instantiate the ChromeWebDriver in code

    ChromeOptions options = new ChromeOptions();
    options.AddArguments("--no-sandbox","--headless");
    return new ChromeDriver(options);
    

Then it came to changes in the dockerfile for deploying this in a container. Because I have a Windows Docker host, I must deploy to a Windows container. I found out that Chrome requires about four or five fonts, and their various iterations, for its default installation to work. The Windows container only has one font in the installation. If you pull up Chrome settings, you'll probably see these fonts. One is for serif fonts, another sans-serif, etc. These fonts are:

  • arial.ttf
  • arialbd.ttf
  • arialbi.ttf
  • ariali.ttf
  • arialn.ttf
  • arialnb.ttf
  • arialni.ttf
  • ariblk.ttf
  • consola.ttf
  • consolab.ttf
  • consolaz.ttf
  • times.ttf
  • timesbi.ttf
  • timesi.ttf

I had to manually install these fonts into the windowsservercore image of Windows.

The resulting dockerfile looks like this:

FROM mcr.microsoft.com/dotnet/sdk:6.0-windowsservercore-ltsc2019
COPY ./test /test
WORKDIR /test
SHELL ["powershell"]
RUN "Add-WindowsFeature Web-WebSockets"
RUN Fonts/Add-Font.ps1 Fonts/Fonts
RUN ["msiexec","/i","chrome.msi","/qn"]
ENTRYPOINT ["dotnet", "test", "--logger:trx"]

In addition, I had to allocate 2g of shared memory in my Docker run statement.

docker run --shm-size="2g"

I found that the Selenium tests kick off about 5 instances of the browser and the web driver, sometimes taking up 600 MB of RAM. This will disappear if you use the driver.quit method after test is complete.

And voila, everything green.

Related