please check if this code is correct. sing OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using WebDriverManager;
using WebDriverManager.DriverConfigs.Impl;

class Program
{
    static void Main()
    {
        // Setup ChromeDriver automatically
        new DriverManager().SetUpDriver(new ChromeConfig());

        // Setup Chrome options
        var options = new ChromeOptions();
        options.AddArgument("--start-maximized");
        options.AddArgument("--disable-notifications");
        // options.AddArgument("--headless"); // Uncomment if you want to run in background
        options.AddArgument("--disable-gpu");
        options.AddArgument("--no-sandbox");
        options.AddArgument("--disable-dev-shm-usage");
        options.AddUserProfilePreference("credentials_enable_service", false);
        options.AddUserProfilePreference("profile.password_manager_enabled", false);

        // Set up custom user agent
        options.AddArgument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");

        using (var driver = new ChromeDriver(options))
        {
            try
            {
                // Create wait object
                var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

                // Navigate to the page
                driver.Navigate().GoToUrl("https://www.forexfactory.com/market/usdcad");

                // Wait for page to load
                Thread.Sleep(5000); // Give some time for the page to load completely

                try
                {
                    // First try with one selector
                    var openButton = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.CssSelector("td.trades_position__cell--detail a")));

                    // Scroll to element
                    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", openButton);
                    Thread.Sleep(500); // Small delay after scroll

                    // Click the button
                    openButton.Click();
                }
                catch
                {
                    // If first selector fails, try alternative selector
                    var openButton = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.CssSelector("a[data-currency='USDCAD']")));

                    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", openButton);
                    Thread.Sleep(500);
                    openButton.Click();
                }

                // Wait for the data to appear and get the value
                var valueElement = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.CssSelector(".tradespositiondetails__section--stats td.positiondetails__long.long.crunched")));

                // Get the text value
                string value = valueElement.Text.Trim();
                Console.WriteLine($"Value: {value}");

                // Take screenshot
                var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
                screenshot.SaveAsFile("screenshot.png");

                // Optional: Save page source for debugging
                File.WriteAllText("page_source.html", driver.PageSource);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred: {ex.Message}");
                Console.WriteLine($"Stack trace: {ex.StackTrace}");

                // Take error screenshot
                var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
                screenshot.SaveAsFile("error_screenshot.png");

                // Save page source on error for debugging
                try
                {
                    File.WriteAllText("error_page_source.html", driver.PageSource);
                }
                catch (Exception pageEx)
                {
                    Console.WriteLine($"Could not save page source: {pageEx.Message}");
                }
            }
            finally
            {
                try
                {
                    // Add a small delay before closing to ensure screenshots are saved
                    Thread.Sleep(1000);
                    driver.Quit();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error closing browser: {ex.Message}");
                }
            }
        }
    }
}