Create cookies using the Java API as follows:
Cookie ck = new Cookie("name", "value");
driver.manage().addCookie(ck);
Create cookies using the Python API as follows:
driver.add_cookie({'name': 'foo', 'value': 'bar'})
public class AddCookie {
public static void main(String[] args) {
// set chrome driver exe path
System.setProperty("webdriver.chrome.driver", "C:/Users/user/Pictures/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(200, TimeUnit.SECONDS);
driver.get("http://google.com");
// set the name and value for the cookie
Cookie coo = new Cookie("karthiQ", "chercher.tech");
// add the cookie
driver.manage().addCookie(coo);
// please donot write the code to close the browser.
}
Cookie coo = new Cookie("karthiQ", "chercher.tech");
// set the name and value for the cookie
Cookie ren = new Cookie("selenium-webdriver.com", "Renamed to chercher.tech");
// add the cookies
driver.manage().addCookie(coo);
driver.manage().addCookie(ren);
// delete the 'karthiQ' cookie
driver.manage().deleteCookieNamed("karthiQ");
// please donot write the code to close the browser.
}
Hiç yorum yok:
Yorum Gönder