I try to add below flag into LocalStorage
and it doesn't work.
localStorage.setItem('ClientRedirectEnabled', 'true');
My code below
public void FlagIntroduce() throws InterruptedException {
Thread.sleep(20000);
LocalStorage localStorage = new LocalStorage() {
@Override
public String getItem(String s) {
return null;
}
@Override
public Set<String> keySet() {
return null;
}
@Override
public void setItem(String s, String s1) {
setItem("ClientRedirectEnabled", "true");
}
@Override
public String removeItem(String s) {
return null;
}
@Override
public void clear() {
}
@Override
public int size() {
return 0;
}
};
}
When test starts in chromedriver I'm opening console and Application bookmark. In Local Storage I don't have key and value which I set in setItem
Check example here LocalStorageTest
@Test
public void testLocalStorageSetAndGetItem() {
ChromeDriver driver = new ChromeDriver();
driver.get("https://www.testurl");
LocalStorage local = ((WebStorage) driver).getLocalStorage();
local.setItem("FOO", "BAR");
local.clear();
}
You can use a JavascriptExecutor
to do the job for you.
If you are using Java as your langugage, following code would help you
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("localStorage.setItem(arguments[0],arguments[1])",key,value));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With