课程: Test Automation with Selenium WebDriver for Java

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Cookies

Cookies

- [Instructor] Websites often store small amounts of data about your activity and preferences in web cookies within your browser. You can access these cookies on the Application tab of your browser's developer tools. Let's use WebDriver to manage cookies. We can start by adding a new Cookie using the cookie class, and we'll set this equal to new Cookie. Inside of the constructor, we'll set a name and a value for the cookie. So let's say that the user prefers a light theme. We can set the name as theme and the value as light. Now we can use WebDriver to store this cookie in the browser. To do so, we'll say driver.manage.addCookie, and we can pass in our cookie that we just created. Then to access cookies within the browser, we can call driver.manage.get. And notice there's a getCookieNamed method, which will get a specific cookie. And getCookies method, which will return all cookies. We'll call getCookieNamed to get the one that we just created. So we'll pass in the name of the cookie,…

内容