【问题标题】:How to add and get cookie value in Chrome with Selenium and Robot Framework如何使用 Selenium 和 Robot Framework 在 Chrome 中添加和获取 cookie 值
【发布时间】:2017-11-28 18:50:48
【问题描述】:

我最近一直在用 Selenium2Library 学习 Robot Framework,但我遇到了一个小问题。

我尝试将 cookie 添加到在 Chrome 中打开的网站,然后检索其值以确保它等于预期值。

resources.txt:

    *** Settings ***
Library           Selenium2Library
Library           OperatingSystem

*** Variables ***
${browser}        chrome

cookieKeywords:

*** Settings ***
Resource          resources.txt

*** Variables ***
${CookieValue}    ${EMPTY}
${ExpectedCookieValue}    somevalue

*** Test Cases ***
CookieTest
    Open Browser    http://www.google.pl    ${browser}
    Add Cookie    CookieTest    somevalue
    ${CookieValue}    Get Cookie Value    CookieTest
    Should Be Equal    ${CookieValue}    ${ExpectedCookieValue}    "Cookie is equal"
    Close Browser

我似乎无法将临时 cookie 添加到使用 chrome 打开的网站...

也许有人遇到过同样的问题?

【问题讨论】:

  • 我刚刚测试了您的代码,它运行良好(也适用于 Firefox)。我什至尝试了不同的 URL,比如google.com。只需确保您拥有最新的 Chrome 驱动程序即可。
  • 我在另一台电脑上试过了,它可以工作,所以我尝试重新安装 Chrome,它可以工作,webdriver 还是一样,所以可能是浏览器版本的问题。

标签: google-chrome selenium cookies robotframework selenium2library


【解决方案1】:

重新安装 Chrome 浏览器有帮助:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-13
    • 2021-06-26
    • 1970-01-01
    • 2019-05-15
    • 2013-06-06
    • 1970-01-01
    • 2021-04-22
    相关资源
    最近更新 更多