Set Cookies in Selenium Webdriver / Run JavaScript

There have been instances where I would run JavaScript snippets from Java's WebDriver

WebDriver driver = new AnyDriverYouWant();
if (driver instanceof JavascriptExecutor) {
Example: ((JavascriptExecutor) driver).executeScript("window.focus()");
You can find more documentation on this in the JavaDocs of JavascriptExecutor.

Now the above example is good with JS being run directly buy what if you want to set a cookie?
If you are new to setting cookies then read this:

Cookie ck = new Cookie("name", "value");
Cookie cookie = new Cookie(name, value, domain, path, expiry);
Read this for Selenium!


Popular posts from this blog

Trim / Remove spaces in Xpath?

RPA - Blue Prism, OpenSpan, Automation Anywhere vs UIPath