Selenium Webdriver C# Page Loading












0














I am just experimenting with Selenium Webdriver, and I am having a couple of issues happen that all seem related that I want to clear up before continuing. When I run the code pasted at the bottom, it takes forever for Selenium to do anything with the browser and it says "waiting for [insert site here]" for a while. Once those are done, then it finally finds the elements and interacts with the page. Sometimes I will get various errors and the errors aren't consistent (but the errors don't break the code it just takes longer until Selenium does what I asked it). And every now and then my antivirus pops up saying it blocked a website (global.ymtracking.com) because it was malware. I feel like this might be related to ads on the webpage and how Selenium loads the web page, but I don't really know since I am new to this. I've never had problems from just visiting this website.



using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace WebScrappingTesting
{
class Program
{
static IWebDriver driver;
static Dictionary<string, Dictionary<string, float>> hockeyStats = new Dictionary<string, Dictionary<string, float>>();
static string TeamName ="";
static float TeamAge;
static float Wins;
static float Losses;

static void Main(string args)
{
driver = new ChromeDriver();

driver.Navigate().GoToUrl("https://www.hockey-reference.com/leagues/NHL_2019.html");

using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", false))
{
file.WriteLine("Team Name,Avg Age,Wins,Losses");
}

for (var year = 2019; year > 2015; year--)
{
Console.WriteLine($"Getting data for {year}");

var rowsOfData = driver.FindElements(By.CssSelector("#stats > tbody > tr"));

for (var i = 1; i <= rowsOfData.Count; i++)
{
TeamName = driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td.left > a")).Text;
float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(3)")).Text, out TeamAge);
float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(5)")).Text, out Wins);
float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(6)")).Text, out Losses);
// TODO: need to change this to a 3 dim dictionary or an object to be able to also record the year of the data
hockeyStats[TeamName] = new Dictionary<string, float>() {
{ "Age", TeamAge },
{ "Wins", Wins },
{ "Losses", Losses }
};
}

foreach (var item in hockeyStats)
{
Console.WriteLine("=============================================================");
Console.WriteLine($"Team Name: {item.Key}, Avg Age: {item.Value["Age"]}");
Console.WriteLine($"Wins {item.Value["Wins"]}, Losses {item.Value["Losses"]}");
}

using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", true))
{
foreach (var item in hockeyStats)
{
file.WriteLine($"{item.Key},{item.Value["Age"]},{item.Value["Wins"]},{item.Value["Losses"]}");
}
}


driver.FindElement(By.LinkText("Previous Season")).Click();
//driver.FindElement(By.CssSelector($"[href*=/leagues/NHL_{year - 1}.html]"));


}

Console.WriteLine("=============================================================");
Console.WriteLine("=============================================================");
Console.WriteLine(@"You file has been saved to C:UsershockeyData.csv");
Console.WriteLine("=============================================================");
Console.WriteLine("=============================================================");

driver.Close();
driver.Dispose();
}
}
}









share|improve this question



























    0














    I am just experimenting with Selenium Webdriver, and I am having a couple of issues happen that all seem related that I want to clear up before continuing. When I run the code pasted at the bottom, it takes forever for Selenium to do anything with the browser and it says "waiting for [insert site here]" for a while. Once those are done, then it finally finds the elements and interacts with the page. Sometimes I will get various errors and the errors aren't consistent (but the errors don't break the code it just takes longer until Selenium does what I asked it). And every now and then my antivirus pops up saying it blocked a website (global.ymtracking.com) because it was malware. I feel like this might be related to ads on the webpage and how Selenium loads the web page, but I don't really know since I am new to this. I've never had problems from just visiting this website.



    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.IO;
    using OpenQA.Selenium;
    using OpenQA.Selenium.Chrome;

    namespace WebScrappingTesting
    {
    class Program
    {
    static IWebDriver driver;
    static Dictionary<string, Dictionary<string, float>> hockeyStats = new Dictionary<string, Dictionary<string, float>>();
    static string TeamName ="";
    static float TeamAge;
    static float Wins;
    static float Losses;

    static void Main(string args)
    {
    driver = new ChromeDriver();

    driver.Navigate().GoToUrl("https://www.hockey-reference.com/leagues/NHL_2019.html");

    using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", false))
    {
    file.WriteLine("Team Name,Avg Age,Wins,Losses");
    }

    for (var year = 2019; year > 2015; year--)
    {
    Console.WriteLine($"Getting data for {year}");

    var rowsOfData = driver.FindElements(By.CssSelector("#stats > tbody > tr"));

    for (var i = 1; i <= rowsOfData.Count; i++)
    {
    TeamName = driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td.left > a")).Text;
    float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(3)")).Text, out TeamAge);
    float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(5)")).Text, out Wins);
    float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(6)")).Text, out Losses);
    // TODO: need to change this to a 3 dim dictionary or an object to be able to also record the year of the data
    hockeyStats[TeamName] = new Dictionary<string, float>() {
    { "Age", TeamAge },
    { "Wins", Wins },
    { "Losses", Losses }
    };
    }

    foreach (var item in hockeyStats)
    {
    Console.WriteLine("=============================================================");
    Console.WriteLine($"Team Name: {item.Key}, Avg Age: {item.Value["Age"]}");
    Console.WriteLine($"Wins {item.Value["Wins"]}, Losses {item.Value["Losses"]}");
    }

    using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", true))
    {
    foreach (var item in hockeyStats)
    {
    file.WriteLine($"{item.Key},{item.Value["Age"]},{item.Value["Wins"]},{item.Value["Losses"]}");
    }
    }


    driver.FindElement(By.LinkText("Previous Season")).Click();
    //driver.FindElement(By.CssSelector($"[href*=/leagues/NHL_{year - 1}.html]"));


    }

    Console.WriteLine("=============================================================");
    Console.WriteLine("=============================================================");
    Console.WriteLine(@"You file has been saved to C:UsershockeyData.csv");
    Console.WriteLine("=============================================================");
    Console.WriteLine("=============================================================");

    driver.Close();
    driver.Dispose();
    }
    }
    }









    share|improve this question

























      0












      0








      0







      I am just experimenting with Selenium Webdriver, and I am having a couple of issues happen that all seem related that I want to clear up before continuing. When I run the code pasted at the bottom, it takes forever for Selenium to do anything with the browser and it says "waiting for [insert site here]" for a while. Once those are done, then it finally finds the elements and interacts with the page. Sometimes I will get various errors and the errors aren't consistent (but the errors don't break the code it just takes longer until Selenium does what I asked it). And every now and then my antivirus pops up saying it blocked a website (global.ymtracking.com) because it was malware. I feel like this might be related to ads on the webpage and how Selenium loads the web page, but I don't really know since I am new to this. I've never had problems from just visiting this website.



      using System;
      using System.Collections.Generic;
      using System.Drawing;
      using System.IO;
      using OpenQA.Selenium;
      using OpenQA.Selenium.Chrome;

      namespace WebScrappingTesting
      {
      class Program
      {
      static IWebDriver driver;
      static Dictionary<string, Dictionary<string, float>> hockeyStats = new Dictionary<string, Dictionary<string, float>>();
      static string TeamName ="";
      static float TeamAge;
      static float Wins;
      static float Losses;

      static void Main(string args)
      {
      driver = new ChromeDriver();

      driver.Navigate().GoToUrl("https://www.hockey-reference.com/leagues/NHL_2019.html");

      using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", false))
      {
      file.WriteLine("Team Name,Avg Age,Wins,Losses");
      }

      for (var year = 2019; year > 2015; year--)
      {
      Console.WriteLine($"Getting data for {year}");

      var rowsOfData = driver.FindElements(By.CssSelector("#stats > tbody > tr"));

      for (var i = 1; i <= rowsOfData.Count; i++)
      {
      TeamName = driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td.left > a")).Text;
      float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(3)")).Text, out TeamAge);
      float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(5)")).Text, out Wins);
      float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(6)")).Text, out Losses);
      // TODO: need to change this to a 3 dim dictionary or an object to be able to also record the year of the data
      hockeyStats[TeamName] = new Dictionary<string, float>() {
      { "Age", TeamAge },
      { "Wins", Wins },
      { "Losses", Losses }
      };
      }

      foreach (var item in hockeyStats)
      {
      Console.WriteLine("=============================================================");
      Console.WriteLine($"Team Name: {item.Key}, Avg Age: {item.Value["Age"]}");
      Console.WriteLine($"Wins {item.Value["Wins"]}, Losses {item.Value["Losses"]}");
      }

      using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", true))
      {
      foreach (var item in hockeyStats)
      {
      file.WriteLine($"{item.Key},{item.Value["Age"]},{item.Value["Wins"]},{item.Value["Losses"]}");
      }
      }


      driver.FindElement(By.LinkText("Previous Season")).Click();
      //driver.FindElement(By.CssSelector($"[href*=/leagues/NHL_{year - 1}.html]"));


      }

      Console.WriteLine("=============================================================");
      Console.WriteLine("=============================================================");
      Console.WriteLine(@"You file has been saved to C:UsershockeyData.csv");
      Console.WriteLine("=============================================================");
      Console.WriteLine("=============================================================");

      driver.Close();
      driver.Dispose();
      }
      }
      }









      share|improve this question













      I am just experimenting with Selenium Webdriver, and I am having a couple of issues happen that all seem related that I want to clear up before continuing. When I run the code pasted at the bottom, it takes forever for Selenium to do anything with the browser and it says "waiting for [insert site here]" for a while. Once those are done, then it finally finds the elements and interacts with the page. Sometimes I will get various errors and the errors aren't consistent (but the errors don't break the code it just takes longer until Selenium does what I asked it). And every now and then my antivirus pops up saying it blocked a website (global.ymtracking.com) because it was malware. I feel like this might be related to ads on the webpage and how Selenium loads the web page, but I don't really know since I am new to this. I've never had problems from just visiting this website.



      using System;
      using System.Collections.Generic;
      using System.Drawing;
      using System.IO;
      using OpenQA.Selenium;
      using OpenQA.Selenium.Chrome;

      namespace WebScrappingTesting
      {
      class Program
      {
      static IWebDriver driver;
      static Dictionary<string, Dictionary<string, float>> hockeyStats = new Dictionary<string, Dictionary<string, float>>();
      static string TeamName ="";
      static float TeamAge;
      static float Wins;
      static float Losses;

      static void Main(string args)
      {
      driver = new ChromeDriver();

      driver.Navigate().GoToUrl("https://www.hockey-reference.com/leagues/NHL_2019.html");

      using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", false))
      {
      file.WriteLine("Team Name,Avg Age,Wins,Losses");
      }

      for (var year = 2019; year > 2015; year--)
      {
      Console.WriteLine($"Getting data for {year}");

      var rowsOfData = driver.FindElements(By.CssSelector("#stats > tbody > tr"));

      for (var i = 1; i <= rowsOfData.Count; i++)
      {
      TeamName = driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td.left > a")).Text;
      float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(3)")).Text, out TeamAge);
      float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(5)")).Text, out Wins);
      float.TryParse(driver.FindElement(By.CssSelector($"#stats > tbody > tr:nth-child({i}) > td:nth-child(6)")).Text, out Losses);
      // TODO: need to change this to a 3 dim dictionary or an object to be able to also record the year of the data
      hockeyStats[TeamName] = new Dictionary<string, float>() {
      { "Age", TeamAge },
      { "Wins", Wins },
      { "Losses", Losses }
      };
      }

      foreach (var item in hockeyStats)
      {
      Console.WriteLine("=============================================================");
      Console.WriteLine($"Team Name: {item.Key}, Avg Age: {item.Value["Age"]}");
      Console.WriteLine($"Wins {item.Value["Wins"]}, Losses {item.Value["Losses"]}");
      }

      using (StreamWriter file = new StreamWriter(@"C:UsershockeyData.csv", true))
      {
      foreach (var item in hockeyStats)
      {
      file.WriteLine($"{item.Key},{item.Value["Age"]},{item.Value["Wins"]},{item.Value["Losses"]}");
      }
      }


      driver.FindElement(By.LinkText("Previous Season")).Click();
      //driver.FindElement(By.CssSelector($"[href*=/leagues/NHL_{year - 1}.html]"));


      }

      Console.WriteLine("=============================================================");
      Console.WriteLine("=============================================================");
      Console.WriteLine(@"You file has been saved to C:UsershockeyData.csv");
      Console.WriteLine("=============================================================");
      Console.WriteLine("=============================================================");

      driver.Close();
      driver.Dispose();
      }
      }
      }






      c# selenium selenium-webdriver






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 at 3:08









      TheBinaryCPA

      307




      307
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It looks like it was related to the website. I ran fiddler and there was a lot going on in the background of that site.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385645%2fselenium-webdriver-c-sharp-page-loading%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It looks like it was related to the website. I ran fiddler and there was a lot going on in the background of that site.






            share|improve this answer


























              0














              It looks like it was related to the website. I ran fiddler and there was a lot going on in the background of that site.






              share|improve this answer
























                0












                0








                0






                It looks like it was related to the website. I ran fiddler and there was a lot going on in the background of that site.






                share|improve this answer












                It looks like it was related to the website. I ran fiddler and there was a lot going on in the background of that site.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 at 19:11









                TheBinaryCPA

                307




                307






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385645%2fselenium-webdriver-c-sharp-page-loading%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    If I really need a card on my start hand, how many mulligans make sense? [duplicate]

                    Alcedinidae

                    Can an atomic nucleus contain both particles and antiparticles? [duplicate]