How to Clear Cookies in Selenium?


How to Handle Cookies in Selenium?



driver.manage().deleteCookieNamed();-
Used For Deleting the specific cookie with cookie name "_fgg"


driver.manage().deleteAllCookies();-
Used for Deleting all the cookies of the domain


Example-


driver.manage().deleteCookieNamed();

package automationtesting;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class HandlingDropDn {

       public static void main(String[] args) throws InterruptedException {
              // TODO Auto-generated method stub
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver driver= new ChromeDriver();
              driver.manage().window().maximize();
              driver.manage().deleteCookieNamed("__fff");
              driver.get("https://www.webfx.com/blog/web-design/50-examples-of-drop-down-navigation-menus-in-web-designs/");
              Select drpdn = new Select(driver.findElement(By.xpath("//*[@id=\"blog-cat-dropdown\"]")));      
              drpdn.selectByVisibleText("INTERNET");
              Select drpdn1 = new Select(driver.findElement(By.xpath("//*[@id=\"blog-cat-dropdown\"]")));
              drpdn1.selectByValue("/blog/social-media/");
              drpdn.deselectByVisibleText("INTERNET");
             
               

        }
       }



driver.manage().deleteAllCookies();

package automationtesting;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class HandlingDropDn {

       public static void main(String[] args) throws InterruptedException {
              // TODO Auto-generated method stub
              System.setProperty("webdriver.chrome.driver","D:\\Sandeep\\Soft\\chromedriver.exe");
              WebDriver driver= new ChromeDriver();
              driver.manage().window().maximize();
              driver.manage().deleteAllCookies();
              driver.get("https://www.webfx.com/blog/web-design/50-examples-of-drop-down-navigation-menus-in-web-designs/");
              Select drpdn = new Select(driver.findElement(By.xpath("//*[@id=\"blog-cat-dropdown\"]")));      
              drpdn.selectByVisibleText("INTERNET");
              Select drpdn1 = new Select(driver.findElement(By.xpath("//*[@id=\"blog-cat-dropdown\"]")));
              drpdn1.selectByValue("/blog/social-media/");
              drpdn.deselectByVisibleText("INTERNET");
             
               

        }
       }


Post a Comment

0 Comments