Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8253725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:58:21+00:00 2026-06-08T00:58:21+00:00

A console app in C# that requests four images in a tight loop sometimes

  • 0

A console app in C# that requests four images in a tight loop sometimes returns a previous request. The code is as below and works against any web site, I typically see 3 or 4 errors per run. I developed this code after reports from people browsing a web site I manage where occasionally a jpeg or script would be loaded when the user requested a HTML page.

I don’t know if it is a Chrome or ChromeDriver issue. If the previous request was an HTML page then you can end up with getting that instead of the image. Seems to be a race condition.

Has anyone else seen this behaviour and can they repeat it with the code below?

class ContentVerify
{
    OpenQA.Selenium.IWebDriver driver;

    readonly System.Collections.Generic.List<string> testUrls = new System.Collections.Generic.List<string>()
    {
        "http://i.imgur.com/zNJvS.jpg",
        "http://i.imgur.com/lzVec.jpg",
        "http://i.imgur.com/rDuhT.jpg",
        "http://i.imgur.com/sZ26q.jpg"
    };

    public void Check()
    {
        driver = new OpenQA.Selenium.Chrome.ChromeDriver(); // Both InternetExplorerDriver and FirefoxDriver work OK.

        for (int i = 0; i < 10; i++)
        {
            TestUrls();
        }
        driver.Quit(); // The driver also crashes on exit, but this seems to be a known bug in Selenium.
    }

    private void TestUrls()
    {
        foreach (var item in testUrls)
        {
            System.Console.WriteLine(item);
            //System.Threading.Thread.Sleep(1); // Uncommenting this makes Chrome & ChromeDriver work as expected.
            driver.Url = item;
            // Requests for images come back as an HTML image tag wrapped in a brief HTML page, like below;
            //<html><body style="margin: 0px;"><img style="-webkit-user-select: none" src="http://i.imgur.com/zNJvS.jpg"></body></html>
            // So the image should always be in the page, but sometimes (not always) we get the previous image requested.
            if (!driver.PageSource.Contains(item))
            {
                System.Console.ForegroundColor = System.ConsoleColor.Red;
                System.Console.WriteLine("Expected: {0}, got: {1}", item, driver.PageSource);
                System.Console.ResetColor();
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T00:58:23+00:00Added an answer on June 8, 2026 at 12:58 am

    It could be that you’re not giving the driver enough time to complete the call and have the page load, so it’ll “return” whatever previous page it had returned. Have you looked into setting up a timeout/wait on the driver?

    EDIT

    With regards to the question of why there is this issue in Chrome but not the other browsers, I’d had to venture a guess and say that it probably has to do with how the different browser engines handle displaying an image directly instead of HTML. I make this assumption due to the fact that this discrepancy as described is not seen when running similar code against an HTML page like the Google home page.

    Each browser wraps the image in some HTML. For example, IE9 wraps as such:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD>
    <BODY><IMG src="[url here]"></BODY></HTML>
    

    Whereas Firefox wraps it like:

    <html>
    <head>
        <meta content="width=device-width; height=device-height;" name="viewport">
        <link href="resource://gre/res/TopLevelImageDocument.css" rel="stylesheet">
        <title>[filename] (JPEG Image, 500&nbsp;×&nbsp;332 pixels)</title>
    </head>
    <body>
        <img alt="[url here]" src="[url here]">
    </body>
    </html>
    

    And finally, Chrome:

    <html>
    <body style="margin: 0px;">
        <img style="-webkit-user-select: none; " src="[url here]" width="500" height="332">
    </body>
    <style type="text/css"></style>
    </html>
    

    Now, I don’t know why the Chrome version causes the webdriver to be unable to detect the pageload. It certainly is the most minimal of the three HTML wrappers, and the w3 validator has a mild panic attack when asked to validate its HTML while the other two validate relatively well.

    Also, as mentioned by mootinator, there have been numerous complaints about the Chrome driver in general so it could be just an issue with the Chrome webdriver itself. I just found the above interesting and thought it might be worthwhile to share.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making multiple AJAX requests inside a loop. Here's my code for that: //
I have a console app that makes a single request to a web page
Im currently doing a console app that has to send scheduled emails. In one
I've got a console app that loads up a datatable; I'd like to export
I have a console app that performs a lengthy process. I am printing out
I have a console app that's geared to be automatically ran as a Scheduled
I created a console app that I want to use in a scheduled package
I'm trying to make a console app that would monitor some process and restart
So I'm trying to make a console app that imposes a time limit to
Hi All, I am running a C# console app that is using the Twitter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.