Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete cookies in Webdriver

There is a .delete_all_visible_cookies method in Selenium. I was surprised to discover that .delete_all_cookies in Webdriver is a part of private API thus is not accessible through @driver instance.

It is a problem for IE since it does not start a clean browser on a new test run as FF.

like image 849
Yulia Avatar asked Sep 14 '11 09:09

Yulia


People also ask

Which WebDriver method will delete the cookies in Selenium?

We can delete cookies on all domains with Selenium. The method deleteAllCookies is used to delete all cookies from the present domain.

What is ContextClick () used for?

ContextClick Method. Right-clicks the mouse at the last known mouse coordinates.

Can Selenium handle cookies?

Selenium WebDriver provides multiple commands for handling the cookies in a website. These Selenium cookies APIs provide you the required mechanism for interacting and querying the cookies. In Selenium Java, these methods are a part of the org. openqa.


2 Answers

From what I know you have to options:

  • When creating the IE instance use capabilities argument:

    DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); caps.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); WebDriver driver = new InternetExplorerDriver(caps);

  • Once initialized, you can use:

    driver.manage().deleteAllCookies()

like image 200
jasalguero Avatar answered Oct 21 '22 03:10

jasalguero


Unfortunately, I was not able to solve this issue by means of Webdriver. Finally, what I do is simply delete the cookies from the command line before running the tests. The line is

RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
like image 32
Yulia Avatar answered Oct 21 '22 03:10

Yulia