how to get localstorage items with Selenium JS

Viewed 28

I'm trying to get localstorage items with nodeJS and selenium but i'm not able to do it, I tried setting new Item and it was working but it didn't work for getting an item I'm sure the Key does exist

const {Builder, By, Key, Util}= require("selenium-webdriver");
async function example(){

    driver= await new Builder().forBrowser("chrome").build();
   // js = ((JavascriptExecutor)driver);
    await driver.get("https://qa-test-digitarm.netlify.app/");
driver.findElement(By.css("input[type='email']")).sendKeys('test@test.com');
driver.findElement(By.css("input[type='password']")).sendKeys('test');

driver.findElement(By.css('.btn')).click();



       // console.log(driver.executeScript("window.localStorage.getItem('is_logged');"));


        driver.executeScript( (function () {
            localStorage.setItem("Id", '{\"_expired\":0,\"_value\":\"133\"}');
           var r= localStorage.getItem("is_logged");
           console.log("test"+r);
        }), );

}

example();
1 Answers

I needed the await before clicking the login button to let the browser load the localstorage before getting it just needed to modify the bellow line await driver.findElement(By.css('.btn')).click();

Related