Notification texts go here Contact Us Buy Now!

[C#] Tutorial Use Cookie in Selemium

[C#] Tutorial Use Cookie in Selemium
Thường các bạn sử dụng Selemium để test hoặc thực hiện một công việc gì đó tự động.
Thì thường chúng ta sẽ điền thông tin username và mật khẩu đăng nhập vào, chúng ta cũng có thể đăng nhập bằng cách khác.
Bằng cách là sử dụng Cookie để đăng nhập tự động.
Trong bài viết này mình sẽ demo login tự động vào trang website One Signal sử dụng Cookie.
Sau khi đăng nhập thành công các bạn mở Web Developer tools để lấy cookie.
Sau đó mình dùng tham số này để add cookie vào Selemium.
[C#] Tutorial Use Cookie in Selemium

Sau khi các bạn có key rồi các bạn code C# như sau:
public void run()
        {
            var driverService = ChromeDriverService.CreateDefaultService();
            driverService.HideCommandPromptWindow = true;
            ChromeOptions options = new ChromeOptions();         
            options.AddArguments("--incognito");
            options.AddArgument(@"--start-maximized");
            options.AddArgument(@"--disable-infobars");
            IWebDriver driver = new ChromeDriver(driverService, options);
            var firingDriver = new EventFiringWebDriver(driver);
            firingDriver.ExceptionThrown += new EventHandler<WebDriverExceptionEventArgs>(firingDriver_ExceptionThrown);
            driver = firingDriver;
            Cookie name = new Cookie("remember_user_token", "my cookie");
           
            driver.Manage().Cookies.DeleteAllCookies();
           
            driver.Navigate().GoToUrl("https://onesignal.com/");
            driver.Manage().Cookies.AddCookie(name);
            driver.Navigate().GoToUrl("https://onesignal.com/");
          
        }

Chúc các bạn thành công với thủ thuật đơn giản này, nếu có vướng mắc gì mọi người có thể bình luận ở phía dưới để mình hỗ trợ nhé hoặc có thể sang trang chính để xem nhé.

تعليقان (2)

  1. MỌI NGƯỜI XEM XÉT CÓ THỂ LÀM CHƯƠNG TRÌNH CHIA SẼ MẬT KHẨU ĐĂNG NHẬP ỨNG DỤNG TỪ COOKIE NHÉ. NA NÁ NHƯ CỦA BÊN APP J2TEAM NHÉ.
    1. chất lượng a (y)
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
NextGen Digital Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...