Ramco Ramco

Ramco Ramco

  • 435
  • 3.4k
  • 547.6k

loop through videos indefinitely

Aug 4 2024 6:59 AM

Hi

  In below code i want to loop through videos indefinitely which are defined in variable videos.

var videos = new List<string>
            {
                "htps://google.com",
                "htps://asp.net",
                "htps://youtu.be/iuMqdF2Lb_4"
            };

await Task.Run(async () =>
            {
                var service = ChromeDriverService.CreateDefaultService();
                service.HideCommandPromptWindow = true;

                _driver = new ChromeDriver(service, options);
                _driver
                    .Manage()
                    .Window
                    .Size = new Size(1024, 768);
                _driver.Navigate().GoToUrl($"{BASE_URL}?v={"_KOo0"}");
                var durationElement = _driver.FindElement(By.XPath(XPATH_TIME));
                var totalDuration = TimeSpan.Parse("00:" + durationElement.Text);
                var btnPlay = _driver.FindElement(By.XPath(XPATH_PLAY));
                btnPlay?.Click();
                while (true)
                {
                    var currentTimeElement = _driver.FindElement(By.ClassName("ytp-time-current"));
                    var currentTime = TimeSpan.Parse(FormatDuration(currentTimeElement.Text));
                    if (currentTime >= totalDuration)
                    {
                        _driver.Navigate().Refresh();
                    }
                }
            });

Thanks


Answers (2)