Hi
I am getting error -
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'Yt_Selenium.Program' threw an exception.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
This exception was originally thrown at this call stack:
[External Code]
Yt_Selenium.Program.Program() in Program.cs
Inner Exception 1:
InvalidOperationException: session not created: This version of ChromeDriver only supports Chrome version 123
Current browser version is 126.0.6478.127 with binary path C:\Program Files\Google\Chrome\Application\chrome.exe (SessionNotCreated)
const string BASE_URL = "youtube.com/watch";
const string XPATH_PLAY = "//button[contains(@class, 'ytp-play-button ytp-button') and @data-title-no-tooltip='Play']";
const string XPATH_MUTE = "//button[contains(@class, 'ytp-mute-button ytp-button')]";
const string XPATH_TIME = "//span[@class = 'ytp-time-duration']";
public static readonly Random _random;
bool _isRunning;
public static TimeSpan _duration;
public static IWebDriver _driver = new ChromeDriver();
static async Task Main(string[] args)
{
await Start();
}
static async Task Start()
{
string timeValue = "";
var options = new ChromeOptions();
var videos = new List<string>
{
"youtu.be/f7Vvy5-EU",
"youtu.be/WI-Kwaua1MM",
"youtu.be/_KOp4WB0o0"
};
await Task.Run(async () =>
{
var service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
_driver = new ChromeDriver(service, options);
_driver
.Manage()
.Window
.Size = new Size(1024, 768);
TimeSpan totalDelay = TimeSpan.Zero;
foreach (var video in videos)
{
_driver.Navigate().GoToUrl($"{BASE_URL}?v={"_KOUp4WB0o0"}");
var btnPlay = _driver.FindElement(By.XPath(XPATH_PLAY));
btnPlay?.Click();
var timeElement = _driver.FindElement(By.XPath(XPATH_TIME));
timeValue = timeElement.GetAttribute("innerText");
}
});
}
Thanks