[英]How do I set a cookie in the selenium webdriver javascript script?
I want to set a cookie on a simple webdriver script: 我想在一个简单的webdriver脚本上设置一个cookie:
WDS.sampleResult.sampleStart();
//WDS.driver.manage().addCookie(new Cookie("connect.sid", "s%3AeexeZcd_-S23Uh30e3Dmd4X9PskWF08s6m5hDurDa5Jj66SupmmiqvKEjAg6HGigl0o0V%2B9R7m4", "api." + rootdomain, "/", null));
// start test
WDS.browser.get("https://api." + rootdomain);
waitForVisible(pkg.By.linkText("Log In"));
WDS.browser.findElement(pkg.By.linkText("Log In")).click()
How do I do that? 我怎么做?
Something like: 就像是:
var cookie = new org.openqa.selenium.Cookie("name","value");
WDS.browser.manage().addCookie(cookie);
should do the trick. 应该可以。
See: 看到:
Using Java From Scripts article to learn how to access Java SDK classes from JavaScript 使用Java From Scripts文章学习如何从JavaScript访问Java SDK类
and 和
The WebDriver Sampler: Your Top 10 Questions Answered guide for some WebDriver Sampler tips WebDriver Sampler:有关WebDriver Sampler技巧的十大常见问题解答指南
You can only set the cookie when the driver has started. 您只能在驱动程序启动后设置cookie。 The driver starts when you do a .get().
执行.get()时,驱动程序启动。 Add the cookie after the .get() and it will work.
在.get()之后添加cookie,它将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.