【问题标题】:How to save my cookies and url to a txt file如何将我的 cookie 和 url 保存到 txt 文件
【发布时间】:2019-10-25 08:58:48
【问题描述】:

所以我可以记录我的 Cookie 和 URL,但我无法尝试将它们设置为变量,请帮助。

我将它们都设置为变量,我只会得到 Promise { }

的输出
driver.findElement(webdriver.By.xpath(`//*[@id="SIZE"]/option[2]`)).click();
driver.findElement(webdriver.By.xpath(`//*[@id="trackpants-ink"]/div/div[3]/form[1]/input[3]`)).click();
setTimeout(function(){
    driver.findElement(webdriver.By.xpath(`//*[@id="js-wrap"]/header/div[2]/form/div/div/div[2]/input`)).click();
    setTimeout(function() {
        driver.getCurrentUrl().then(url=> console.log(url)).catch(err=>console.log(err));
        setInterval(function() {
            driver.manage().getCookies().then(function (cookies) {
                console.log(cookies);
            }); 
        }, 2000);
    }, 2000);
}, 5000);
}

我想将它设置为一个变量(这是 cookie)

driver.manage().getCookies().then(function (cookies) {
console.log(cookies);
});

我想将它设置为一个变量(这是 URL)

driver.getCurrentUrl().then(url=> console.log(url)).catch(err=>console.log(err));

这两个都在运行时输出到控制台,但它不允许我将它们转换为变量。 感谢您的帮助:)

【问题讨论】:

    标签: javascript node.js selenium selenium-webdriver fs


    【解决方案1】:

    我认为你可以使用“让”。试试下面的:

    let cookiesData;
    driver.manage().getCookies().then(function (cookies) {
    console.log(cookies);
    cookiesData = cookies;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多