Hi Naimish
I have below code. What is happening . It opens 1,2,3, video but only last one is run. I want first video should run then second,third and so on.
C#
foreach (var video in videos)
{
_driver.Navigate().GoToUrl(video);
await Task.Delay(1000); // This is just to simulate the time it takes to play the video
}
var videos = new List
{
"youtu.be/f7V5l5-EU",
"youtu.be/WI-KwauaM",
"youtu.be/_KOUp4WBo0",
"youtu.be/5CPMILQrE"
};Thanks

Jignesh KumarRank #91 · 22.9K reputationPosted Apr 30, 2024, 1:05 AM EDT
Hello Ramco,
Please do below change,
foreach (var video in videos) { _driver.Navigate().GoToUrl(video); await Task.Delay(1000); // This is just to simulate the time it takes to play the video // Wait for a longer duration to simulate watching the entire video await Task.Delay(TimeSpan.FromMinutes(5)); // Simulate watching the video for 5 minutes }Ramco RamcoRank #462 · 5.4K reputationPosted Apr 30, 2024, 1:30 AM EDT
Hi Jignesh
I am trying below code but it is not working. In timevalue it gives video time say 1:20. I want after completing this and a gap of few seconds it should run second video and so on
foreach (var video in videos) { _driver.Navigate().GoToUrl(video); var timeElement = _driver.FindElement(By.XPath(XPATH_TIME)); timeValue = timeElement.GetAttribute("innerText"); await Task.Delay(1000); // This is just to simulate the time it takes to play the video await Task.Delay(TimeSpan.FromMinutes(1)); // Simulate watching the video for 5 minutes }Thanks
Jignesh KumarRank #91 · 22.9K reputationPosted Apr 30, 2024, 1:55 AM EDT
Hello Ramco,
You can use the time value attribute to delay using timespan, if you do not get any values then you can set the default time value as per your requirement
foreach (var video in videos) { _driver.Navigate().GoToUrl(video); var timeElement = _driver.FindElement(By.XPath(XPATH_TIME)); string timeValue = timeElement.GetAttribute("innerText"); // Parse the timeValue to TimeSpan if (TimeSpan.TryParse(timeValue, out TimeSpan videoDuration)) { // Delay by the duration of the video await Task.Delay(videoDuration); } else { // Handle parsing error, maybe log it or use a default delay Console.WriteLine("Failed to parse video duration: " + timeValue); await Task.Delay(TimeSpan.FromMinutes(1)); // Default delay } }Jignesh KumarRank #91 · 22.9K reputationPosted May 1, 2024, 2:34 AM EDT
@Ramco Have you check on last reply. It should work for you.
Ramco RamcoRank #462 · 5.4K reputationPosted May 1, 2024, 2:47 AM EDT
Hi Jignesh
With the below code only my first video runs.
Thanks
Jignesh KumarRank #91 · 22.9K reputationPosted May 1, 2024, 3:11 AM EDT
Have you check first video time span. You need to wait until that video complete.
Ramco RamcoRank #462 · 5.4K reputationPosted May 1, 2024, 3:25 AM EDT
Hi Jignesh
After my first video youtube starts its own suggested video. I want that my second video should run and so on
Thnaks