首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在selenium中设置cookies

问在selenium中设置cookies
EN

Stack Overflow用户
提问于 2016-06-29 20:59:16
回答 0查看 1.1K关注 0票数 1

我正在尝试使用以下代码设置cookies

代码语言:javascript
复制
WebDriver driver=new FirefoxDriver();
driver.get("https://mail.google.com");
driver.findElement(By.id("Email")).sendKeys("example@gmail.com");
driver.findElement(By.id("next")).click();
Thread.sleep(3000);
driver.findElement(By.id("Passwd")).sendKeys("example999");
driver.findElement(By.id("signIn")).click();
Thread.sleep(3000);
Set<Cookie> cookies=driver.manage().getCookies();
driver.quit();
driver=new FirefoxDriver();
for(Cookie a:cookies){  
    driver.manage().addCookie(a);   
}
driver.get("https://mail.google.com");

它抛出的错误如下:

代码语言:javascript
复制
org.openqa.selenium.InvalidCookieDomainException:
You may only set cookies for the current domain
Command duration or timeout: 55 milliseconds
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38100323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档