我有这个代码:
System.setProperty("webdriver.gecko.driver", "D:\\chromedriver");
WebDriver webDriver = new ChromeDriver();
webDriver.get("https://example.com");
Thread.sleep(3000);
Cookie cookie = new Cookie.Builder("dsdsdsds", "dsdsds").path("/").sameSite("None").expiresOn(new Date()).isSecure(true).build();
webDriver.manage().deleteAllCookies();
webDriver.manage().getCookies().add(cookie);
webDriver.manage().getCookies().add(new Cookie("__Secure-access_token", accessToken));
webDriver.manage().getCookies().add(new Cookie("__Secure-id_token", secIdToken));
webDriver.manage().getCookies().add(new Cookie("__Secure-id_hint", idHint));
webDriver.manage().getCookies().add(new Cookie("a12l-csrf-prod", csrfToken));
webDriver.manage().getCookies().add(new Cookie("id_token", idToken));
webDriver.navigate().refresh();
webDriver.manage().getCookies().forEach(System.out::println);
但是,重新加载后,会呈现标准页面cookie,但我的自定义页面不会呈现。该怎么办?
您正在将cookie添加到从
set
返回的getCookies()
中,您需要将其添加到WebDriver
webDriver.manage().add(new Cookie("__Secure-access_token", accessToken));