【问题标题】:Any way to set value for a particular cookie in selenium?有什么方法可以为硒中的特定 cookie 设置值?
【发布时间】:2015-07-21 19:17:44
【问题描述】:

我尝试过使用 driver.manage().getCookies().add(new Cookie("cookie-name","cookie-value")); 但这并没有设置 Cookie 的值。

【问题讨论】:

    标签: cookies selenium-webdriver


    【解决方案1】:

    它应该可以工作。

    driver.get(yourAppUrl);  //this statement must execute before you set cookies.
    Cookie newCookie= new Cookie(name, value);
    driver.manage().addCookie(newCookie);
    

    【讨论】:

    • Prateek 并没有真正起作用。我将上述代码用于 AndroidDriver。以下是日志:
    • 没有工作,使用上面的AndroidDriver代码。日志:org.openqa.selenium.WebDriverException:发生错误(警告:服务器未提供任何堆栈跟踪信息)驱动程序信息:io.appium.java_client.android.AndroidDriver Capabilities [{platform=ANDROID, acceptSslCerts=true, javascriptEnabled= true,browserName=chrome,chrome={},rotatable=false,locationContextEnabled=true,mobileEmulationEnabled=false,version=43.0.2357.93,takesHeapSnapshot=true,cssSelectorsEnabled=true,databaseEnabled=false,handlesAlerts=true,browserConnectionEnabled=false,nativeEvents =true}]
    • 你能告诉我你正在使用的代码或存储库的 Github 链接吗?
    • DesiredCapabilities 能力 = new DesiredCapabilities();能力.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");能力.setCapability(MobileCapabilityType.PLATFORM_VERSION,“4.4”);能力.setCapability(MobileCapabilityType.DEVICE_NAME, "");能力.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome"); driver = new AndroidDriver(new URL("127.0.0.1:4723/wd/hub"), capabilities); Cookie c = new Cookie("abRand", "1"); driver.manage().addCookie(c);
    • 上面共享的日志在以下行抛出错误:driver.manage().addCookie(c);我是否缺少添加一些依赖项或功能?
    猜你喜欢
    • 2015-07-24
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多