I have multiple test cases in that some of them are having login into website to test the functionality and some other are not required to login to test the functionality.

Issue is when one test case is login to site to test the functionality and it is storing the login session due to that my next test case which doesn't require login is getting failed.

So I would like to know how to clear cache , History in phantomjs browser

  • What test framework do you use? JUnit of TestNG or some similar one?
    – Alexey R.
    Mar 22, 2018 at 8:32
  • My environment is selenium with Java TestNG and Maven
    – QAMember
    Mar 22, 2018 at 9:01
  • So you should have BeforeTest and AfterTest that would instantiate new driver and then close it respectively. This should clear the caches.
    – Alexey R.
    Mar 22, 2018 at 9:05
  • Yes I am doing the same but still issue is raising. Especially in PhantomJS browser in remaining browsers I am not having this issue
    – QAMember
    Mar 22, 2018 at 9:44
  • Try this one phantomjs.org/api/phantom/method/clear-cookies.html
    – Alexey R.
    Mar 22, 2018 at 11:36

1 Answer 1


Update to PhantomJS 2.0 and Run using JavascriptExecutor class in selenium: (JavascriptExecutor) driver.executeScript(" var page = this; page.clearMemoryCache(); page.close();");

As mentioned Here.

  • I tried above code but getting error "errorMessage":"Can't find variable: page"
    – QAMember
    Mar 22, 2018 at 10:21
  • Updated answer with full code. Mar 22, 2018 at 10:25
  • Still getting error "errorMessage":"undefined is not a constructor (evaluating 'page.clearMemoryCache()')
    – QAMember
    Mar 22, 2018 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.