Untitled

                Never    
Text
       
static class fewtadrivers
{

    public static void NextProfile()
    {
        try
        {
            fewtadrivers.Driver.Quit();
        }
        catch (Exception)
        {

        }
        int profile_no = Convert.ToInt32(ProfileNumber) + 1;

        while (DataLoader.CheckProfile(profile_no) == false)
        {

            if (profile_no > 200)
            {
                Console.WriteLine("Look like the process has finished");
                Console.ReadLine();
                break;
            }
            profile_no++;
        }


        ProfileNumber = profile_no.ToString();
        System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcesses();
        foreach (var p in proc)
        {
            if (p.ProcessName.ToLower().Contains("chromedriv"))
            {
                p.Kill();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Safely Removed {0}", "ChromeDriver");
                Console.ForegroundColor = ConsoleColor.White;

            }
        }
        ChromeDriverService cServicex = ChromeDriverService.CreateDefaultService();
        ChromeOptions optionsx = new ChromeOptions();

        optionsx.AddArgument("--disable-popup-blocking");
        //optionsx.AddExcludedArgument("enable-automation");
        //optionsx.AddAdditionalCapability("useAutomationExtension", false);
        optionsx.AddArgument($"user-data-dir={GetChromePath().ToLower()}");
        optionsx.AddArgument($"--profile-directory=profile {profile_no}");

        //optionsx.AddArguments("window-size=1024,768");
        //3840 x 2160
        optionsx.AddArgument("--disable-extensions");
        cServicex.HideCommandPromptWindow = true;
        fewtadrivers.Driver = new ChromeDriver(cServicex, optionsx);
        fewtadrivers.Driver.Manage().Window.Maximize();
    }
    //Attributes
    private static IWebDriver driver;
    //Properties
    public static IWebDriver Driver { get { return driver; } set { driver = value; } }
    public static string ProfileNumber = "";
    public static int max_profile = 108;
    public static void StartProfile(string profile_number)
    {
        ProfileNumber = profile_number;
        System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcesses();
        foreach (var p in proc)
        {
            if (p.ProcessName.ToLower().Contains("chromedriv") || p.ProcessName.ToLower().Contains("chrome"))
            {
                try
                {
 p.Kill();
                }
                catch (Exception)
                {

                   
                }
               

                Console.ForegroundColor = ConsoleColor.Green;
                //  Console.WriteLine("Safely Removed {0}","ChromeDriver");
                Console.ForegroundColor = ConsoleColor.White;

            }
        }
        ChromeDriverService cServicex = ChromeDriverService.CreateDefaultService();
        ChromeOptions optionsx = new ChromeOptions();

        optionsx.AddArgument("--disable-popup-blocking");
        optionsx.AddExcludedArgument("enable-automation");
        optionsx.AddAdditionalCapability("useAutomationExtension", false);
        optionsx.AddArgument($"user-data-dir={GetChromePath()}");
        optionsx.AddArgument($"--profile-directory=profile {profile_number}");
        //optionsx.AddArgument($"--headless");

        if (globalSetting.DownloadImages)
        {
            optionsx.AddArgument("--blink-settings=imagesEnabled=false");

        }
        if (globalSetting.Headless)
        {
            optionsx.AddArgument("--headless");

        }
        // optionsx.AddArguments("window-size=1024,768");
        //3840 x 2160
        optionsx.AddArgument("--disable-extensions");
        cServicex.HideCommandPromptWindow = true;
        fewtadrivers.Driver = new ChromeDriver(cServicex, optionsx);
        fewtadrivers.Driver.Manage().Window.Maximize();
    }
    public static void StartProfile1()
    {

        ChromeDriverService cServicex = ChromeDriverService.CreateDefaultService();
        ChromeOptions optionsx = new ChromeOptions();

        optionsx.AddArgument("--disable-popup-blocking");
        optionsx.AddExcludedArgument("enable-automation");
        optionsx.AddAdditionalCapability("useAutomationExtension", false);
        optionsx.AddArgument($"--headless");


        optionsx.AddArgument("--blink-settings=imagesEnabled=false");


        optionsx.AddArgument("--headless");


        // optionsx.AddArguments("window-size=1024,768");
        //3840 x 2160
        optionsx.AddArgument("--disable-extensions");
        cServicex.HideCommandPromptWindow = true;
        fewtadrivers.Driver = new ChromeDriver(cServicex, optionsx);
        fewtadrivers.Driver.Manage().Window.Maximize();
    }
    public static void StartProfileSingle()
    {

        System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcesses();
        foreach (var p in proc)
        {
            if (p.ProcessName.ToLower().Contains("chromedriv"))
            {
                p.Kill();
                Console.ForegroundColor = ConsoleColor.Green;
                //  Console.WriteLine("Safely Removed {0}","ChromeDriver");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
        ChromeDriverService cServicex = ChromeDriverService.CreateDefaultService();
        ChromeOptions optionsx = new ChromeOptions();

        optionsx.AddArgument("--disable-popup-blocking");
        optionsx.AddExcludedArgument("enable-automation");
        optionsx.AddAdditionalCapability("useAutomationExtension", false);
        //    optionsx.AddArgument($"user-data-dir={GetChromePath()}");
        optionsx.AddArgument($"--headless");

        if (globalSetting.DownloadImages)
        {
            optionsx.AddArgument("--blink-settings=imagesEnabled=false");

        }
        if (globalSetting.Headless)
        {
            optionsx.AddArgument("--headless");

        }
        // optionsx.AddArguments("window-size=1024,768");
        //3840 x 2160
        optionsx.AddArgument("--disable-extensions");
        cServicex.HideCommandPromptWindow = true;
        fewtadrivers.Driver = new ChromeDriver(cServicex, optionsx);
        fewtadrivers.Driver.Manage().Window.Maximize();
    }
    public static string GetChromePath()
    {
        string[] s = WindowsIdentity.GetCurrent().Name.Split('\\');
        // Console.WriteLine("username is {0}",s[1]);

        return $@"C:\Users\{s[1]}\AppData\Local\Google\Chrome\User Data\";
    }
    public static void ScrollToElement(IWebElement Element)
    {
        IJavaScriptExecutor ScrollToView = (IJavaScriptExecutor)fewtadrivers.Driver;
        ScrollToView.ExecuteScript("arguments[0].scrollIntoView(true);", Element);
    }


}

Raw Text