如何使用Selenium清除HTML5中的会话详细信息?

时间:2018-01-22 16:20:46

标签: selenium groovy katalon-studio

我使用以下方法清除会话存储值

public static void CleanCache()
{
WebDriver driver = new WebDriver()
LocalStorage local =((WebStorage)driver).getSessionStorage().clear()
}

但是得到以下错误

获取以下错误:

01-22-2018 03:16:59 PM - [ERROR]  - Cannot cast object 'CInternetExplorerDriver: internet explorer on WINDOWS (c0f0e132-d574-48c3-a339-9180555b0e33)' with class 'com.kms.katalon.selenium.driver.CInternetExplorerDriver' to class 'org.openqa.selenium.html5.WebStorage'
01-22-2018 03:16:59 PM - [ERROR]  - Test Cases/01_UserManagement/Login FAILED because (of) org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'CInternetExplorerDriver: internet explorer on WINDOWS (c0f0e132-d574-48c3-a339-9180555b0e33)' with class 'com.kms.katalon.selenium.driver.CInternetExplorerDriver' to class 'org.openqa.selenium.html5.WebStorage'

任何帮助都会受到赞赏吗?

1 个答案:

答案 0 :(得分:1)

通过查看错误,driver无法转换为WebStorage。将代码更改为以下内容:

public static void CleanCache()
{
    WebDriver driver = new WebDriver()
    driver.getSessionStorage().clear()
}

如果你找不到其他有用的东西,你可以随时使用JS

window.sessionStorage.clear()

有关详细信息,请参阅this