2017-04-12

Taking Screenshot & Handling Cookies

Screenshot Code

 public string timestamp()
        {
            return new SimpleDateFormat("yyyy-MM-dd HH-mm-ss").format(new Date());
        }



//Take screenshot and save to file
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
string fileToSave = "screenshot_" + timestamp() + ".png";
ss.SaveAsFile(fileToSave, ScreenshotImageFormat.Png);


//Simplified As:
((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(fileToSave, ScreenshotImageFormat.Png);



Handling Cookies

driver.manage().getCookies();   // Return The List of all Cookies
driver.manage().getCookieNamed(arg0);  //Return specific cookie according to name
driver.manage().addCookie(arg0);   //Create and add the cookie
driver.manage().deleteCookie(arg0);  // Delete specific cookie
driver.manage().deleteCookieNamed(arg0); // Delete specific cookie according Name
driver.manage().deleteAllCookies();  // Delete all cookies

No comments:

Post a Comment

Setup VNC on Ubuntu 20.04

  sudo apt update sudo apt install xfce4 xfce4-goodies sudo apt install tigervnc-standalone-server sudo apt install tightvncserver vncserver...